📄 ixethdbnpeadaptor.c
字号:
* * @return none * * @internal */IX_ETH_DB_PUBLICvoid ixEthDBNPETreeWrite(IxEthDBRecordType type, UINT32 totalSize, void *baseAddress, MacTreeNode *tree, UINT32 *epDelta, UINT32 *blocks){ MacTreeNodeStack *stack; UINT32 currentSize = 0; UINT32 offset = 0; UINT32 maxOffset = 0; stack = ixOsalCacheDmaMalloc(sizeof (MacTreeNodeStack)); if (stack == NULL) { ERROR_LOG("DB: (NPEAdaptor) failed to allocate the node stack for learning tree linearization, out of memory?\n"); return; } /* zero out empty root */ currentSize = ixEthDBNPENodeWrite[type](NULL, baseAddress, 0, totalSize); NODE_STACK_INIT(stack); if (tree != NULL) { /* push tree root at offset 1 */ NODE_STACK_PUSH(stack, tree, 1); } while (NODE_STACK_NONEMPTY(stack)) { MacTreeNode *node; NODE_STACK_POP(stack, node, offset); /* Add node to NPE table at position indicated by offset */ /* In the case where a node is NULL, the NodeWrite function will zero out * the memory based on the offset. * In the case where the given offset goes past totalSize, no entry is written */ currentSize = ixEthDBNPENodeWrite[type](node, baseAddress, offset, totalSize); if ((node != NULL) && (currentSize <= totalSize)) { IX_ETH_DB_NPE_VERBOSE_TRACE("DB: (NPEAdaptor) writing MAC [%s] at offset %d\n", mac2string(node->descriptor->macAddress), offset); if(maxOffset<offset) maxOffset = offset; NODE_STACK_PUSH(stack, node->left, LEFT_CHILD_OFFSET(offset)); NODE_STACK_PUSH(stack, node->right, RIGHT_CHILD_OFFSET(offset)); } } /* this extra write is done to determine if any more empty entries in the table need * to be cleared. */ currentSize = ixEthDBNPENodeWrite[type](NULL, baseAddress, maxOffset+1, totalSize); if (currentSize < totalSize) { /* zero out rest of the tree */ IX_ETH_DB_NPE_TRACE("DB: (NPEAdaptor) Clearing rest of tree\n"); /* zero out the rest of the table */ memset((void *) (((UINT32) baseAddress) + currentSize), 0, (totalSize - currentSize)); } else { currentSize = totalSize ; } /* flush cache */ IX_OSAL_CACHE_FLUSH(baseAddress, totalSize); IX_ETH_DB_NPE_TRACE("DB: (NPEAdaptor) Ethernet learning/filtering tree XScale wrote at address 0x%08X (max %d bytes):\n\n", (UINT32) baseAddress, totalSize); /* compute number of 64-byte blocks */ if (blocks != NULL) { *blocks = currentSize ? 1 + ((currentSize - 1) / 64) : 0; IX_ETH_DB_NPE_TRACE("DB: (NPEAdaptor) Wrote %d 64-byte blocks\n", *blocks); } /* compute epDelta - start index for binary search */ if (epDelta != NULL) { UINT32 deltaIndex = 0; *epDelta = 0; for (; deltaIndex < IX_ETH_DB_MAX_DELTA_ZONES ; deltaIndex ++) { if (ixEthDBEPDeltaOffset[type][deltaIndex] >= maxOffset) { *epDelta = ixEthDBEPDelta[type][deltaIndex]; break; } } IX_ETH_DB_NPE_TRACE("DB: (NPEAdaptor) Computed epDelta %d (based on maxOffset %d)\n", *epDelta, maxOffset); } ixOsalCacheDmaFree(stack);}/** * @brief implements a dummy node serialization function * * @param address address of where the node is to be serialized (unused) * @param node tree node to be serialized (unused) * * This function is registered for safety reasons and should * never be called. It will display an error message if this * function is called. * * @return none * * @internal */IX_ETH_DB_PRIVATEUINT32 ixEthDBNullSerialize(MacTreeNode *node, void *address, UINT32 offset, UINT32 maxSize){ IX_ETH_DB_NPE_TRACE("DB: (NPEAdaptor) Warning, the NullSerialize function was called, wrong record type?\n"); return 0;}/** * @brief writes a filtering entry in NPE linear format * * @param node: node to be written * @param baseAddress: base memory address to write node to * @param entryOffset: number of entries to offset * @param maxByteSize: maximum size of memory area to write to * * @return the byte offset of the next entry * * Used by @ref ixEthDBNPETreeWrite to liniarize a search tree * in NPE-readable format. * * @internal */IX_ETH_DB_PRIVATEUINT32 ixEthDBNPELearningNodeWrite(MacTreeNode *node, void *baseAddress, UINT32 entryOffset, UINT32 maxByteSize){ void *address = (void*) ((UINT32)baseAddress + (entryOffset * ELT_ENTRY_SIZE)); UINT32 byteSize = (entryOffset+1) * ELT_ENTRY_SIZE; /* if the size is greater than max, do nothing and return the max */ if(byteSize > maxByteSize) return byteSize; /* If node is NULL, zero out this record in memory */ if(NULL == node) { memset(address, 0, ELT_ENTRY_SIZE); return byteSize; } /* copy mac address */ memcpy(address, node->descriptor->macAddress, IX_IEEE803_MAC_ADDRESS_SIZE); /* copy port ID */ NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_ELT_PORT_ID_OFFSET) = IX_ETHNPE_PHYSICAL_ID_TO_LOGICAL_ID(node->descriptor->portID); /* copy flags (valid and not active, as the NPE sets it to active) and clear reserved section (bits 2-7) */ NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_ELT_FLAGS_OFFSET) = (UINT8) IX_EDB_FLAGS_INACTIVE_VALID; IX_ETH_DB_NPE_VERBOSE_TRACE("DB: (NPEAdaptor) writing ELT node 0x%08x:0x%08x\n", * (UINT32 *) address, * (((UINT32 *) (address)) + 1)); return byteSize;}/** * @brief writes a WiFi header conversion record in * NPE linear format * * @param node: node to be written * @param baseAddress: base memory address to write node to * @param entryOffset: number of entries to offset * @param maxByteSize: maximum size of memory area to write to * * @return the byte offset of the next entry * * Used by @ref ixEthDBNPETreeWrite to liniarize a search tree * in NPE-readable format. * * @internal */IX_ETH_DB_PRIVATEUINT32 ixEthDBNPEWiFiNodeWrite(MacTreeNode *node, void *baseAddress, UINT32 entryOffset, UINT32 maxByteSize){ void *address = (void*) ((UINT32)baseAddress + (entryOffset * ELT_ENTRY_SIZE)); UINT32 byteSize = (entryOffset+1) * ELT_ENTRY_SIZE; /* if the size is greater than max, do nothing and return the max */ if(byteSize > maxByteSize) return byteSize; /* If node is NULL, zero out this record in memory */ if(NULL == node) { memset(address, 0, ELT_ENTRY_SIZE); return byteSize; } /* copy mac address */ memcpy(address, node->descriptor->macAddress, IX_IEEE803_MAC_ADDRESS_SIZE); /* copy index */ NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_WIFI_INDEX_OFFSET) = node->descriptor->recordData.wifiData.recIndex; /* copy flags (type and valid) */ NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_WIFI_FLAGS_OFFSET) = node->descriptor->recordData.wifiData.padLength << 4 | node->descriptor->recordData.wifiData.recType << 1 | IX_EDB_FLAGS_VALID; return byteSize;}/** * @brief writes a WiFi gateway header conversion record in * NPE linear format * * @param node: node to be written * @param baseAddress: base memory address to write node to * @param entryOffset: number of entries to offset * @param maxByteSize: maximum size of memory area to write to * * @return the byte offset of the next entry * * Used by @ref ixEthDBNPETreeWrite to liniarize a search tree * in NPE-readable format. * * @internal */IX_ETH_DB_PUBLICUINT32 ixEthDBNPEGatewayNodeWrite(MacTreeNode *node, void *baseAddress, UINT32 entryOffset, UINT32 maxByteSize){ void *address = (void*) ((UINT32)baseAddress + (entryOffset * ELT_ENTRY_SIZE)); UINT32 byteSize = (entryOffset+1) * ELT_ENTRY_SIZE; /* if the size is greater than max, do nothing and return the max */ if(byteSize > maxByteSize) return byteSize; /* If node is NULL, zero out this record in memory */ if(NULL == node) { memset(address, 0, ELT_ENTRY_SIZE); return byteSize; } /* copy mac address */ memcpy(address, node->descriptor->recordData.wifiData.gwMacAddress, IX_IEEE803_MAC_ADDRESS_SIZE); /* set reserved field, two bytes */ NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_GW_RESERVED_OFFSET) = 0; NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_GW_RESERVED_OFFSET + 1) = 0; return byteSize;}/** * @brief writes a WiFi bssid header conversion record in * NPE linear format * * @param node: node to be written * @param baseAddress: base memory address to write node to * @param entryOffset: number of entries to offset * @param maxByteSize: maximum size of memory area to write to * * @return the byte offset of the next entry * * Used by @ref ixEthDBNPETreeWrite to liniarize a search tree * in NPE-readable format. * * @internal */IX_ETH_DB_PUBLICUINT32 ixEthDBNPEBssidNodeWrite(MacTreeNode *node, void *baseAddress, UINT32 entryOffset, UINT32 maxByteSize){ void *address = (void*) ((UINT32)baseAddress + (entryOffset * ELT_ENTRY_SIZE)); UINT32 byteSize = (entryOffset+1) * ELT_ENTRY_SIZE; /* if the size is greater than max, do nothing and return the max */ if(byteSize > maxByteSize) return byteSize; /* If node is NULL, zero out this record in memory */ if(NULL == node) { memset(address, 0, ELT_ENTRY_SIZE); return byteSize; } /* copy mac address */ memcpy(address, node->descriptor->recordData.wifiData.bssid, IX_IEEE803_MAC_ADDRESS_SIZE); /* set destination port and reserved fields */ NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_BSSID_DEST_PORT_OFFSET) = node->descriptor->recordData.wifiData.logicalPortID; NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_BSSID_RESERVED_OFFSET) = 0; return byteSize;}/** * @brief writes a masked firewall record in * NPE linear format * * @param node: node to be written * @param baseAddress: base memory address to write node to
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -