4 * @brief Implementation of the public API
7 * IXP400 SW Release version 2.0
9 * -- Copyright Notice --
12 * Copyright 2001-2005, Intel Corporation.
13 * All rights reserved.
16 * SPDX-License-Identifier: BSD-3-Clause
18 * -- End of Copyright Notice --
21 #include "IxEthDB_p.h"
23 extern HashTable dbHashtable;
24 IX_ETH_DB_PRIVATE void ixEthDBPortInfoShow(IxEthDBPortId portID, IxEthDBRecordType recordFilter);
25 IX_ETH_DB_PRIVATE IxEthDBStatus ixEthDBHeaderShow(IxEthDBRecordType recordFilter);
26 IX_ETH_DB_PUBLIC IxEthDBStatus ixEthDBDependencyPortMapShow(IxEthDBPortId portID, IxEthDBPortMap map);
29 * @brief displays a port dependency map
31 * @param portID ID of the port
32 * @param map port map to display
34 * @return IX_ETH_DB_SUCCESS if the operation completed
38 IxEthDBStatus ixEthDBDependencyPortMapShow(IxEthDBPortId portID, IxEthDBPortMap map)
41 BOOL mapSelf = true, mapNone = true, firstPort = true;
43 /* dependency port maps */
44 printf("Dependency port map: ");
46 /* browse the port map */
47 for (portIndex = 0 ; portIndex < IX_ETH_DB_NUMBER_OF_PORTS ; portIndex++)
49 if (IS_PORT_INCLUDED(portIndex, map))
53 if (portIndex != portID)
58 printf("%s%d", firstPort ? "{" : ", ", portIndex);
69 printf("%s (%s)\n", firstPort ? "" : "}", mapSelf ? "self" : mapNone ? "none" : "group");
71 return IX_ETH_DB_SUCCESS;
75 * @brief displays all the filtering records belonging to a port
77 * @param portID ID of the port to display
79 * Note that this function is documented in the main component
80 * header file, IxEthDB.h.
82 * @warning deprecated, use @ref ixEthDBFilteringDatabaseShowRecords()
83 * instead. Calling this function is equivalent to calling
84 * ixEthDBFilteringDatabaseShowRecords(portID, IX_ETH_DB_FILTERING_RECORD)
87 IxEthDBStatus ixEthDBFilteringDatabaseShow(IxEthDBPortId portID)
89 IxEthDBStatus local_result;
90 HashIterator iterator;
92 UINT32 recordCount = 0;
94 IX_ETH_DB_CHECK_PORT(portID);
96 IX_ETH_DB_CHECK_SINGLE_NPE(portID);
98 portInfo = &ixEthDBPortInfo[portID];
100 /* display table header */
101 printf("Ethernet database records for port ID [%d]\n", portID);
103 ixEthDBDependencyPortMapShow(portID, portInfo->dependencyPortMap);
105 if (ixEthDBPortDefinitions[portID].type == IX_ETH_NPE)
107 printf("NPE updates are %s\n\n", portInfo->updateMethod.updateEnabled ? "enabled" : "disabled");
111 printf("updates disabled (not an NPE)\n\n");
114 printf(" MAC address | Age | Type \n");
115 printf("___________________________________\n");
117 /* browse database */
118 BUSY_RETRY(ixEthDBInitHashIterator(&dbHashtable, &iterator));
120 while (IS_ITERATOR_VALID(&iterator))
122 MacDescriptor *descriptor = (MacDescriptor *) iterator.node->data;
124 if (descriptor->portID == portID && descriptor->type == IX_ETH_DB_FILTERING_RECORD)
129 printf(" %02X:%02X:%02X:%02X:%02X:%02X | %5d | %s\n",
130 descriptor->macAddress[0],
131 descriptor->macAddress[1],
132 descriptor->macAddress[2],
133 descriptor->macAddress[3],
134 descriptor->macAddress[4],
135 descriptor->macAddress[5],
136 descriptor->recordData.filteringData.age,
137 descriptor->recordData.filteringData.staticEntry ? "static" : "dynamic");
140 /* move to the next record */
141 BUSY_RETRY_WITH_RESULT(ixEthDBIncrementHashIterator(&dbHashtable, &iterator), local_result);
144 if (local_result == IX_ETH_DB_BUSY)
146 return IX_ETH_DB_FAIL;
150 /* display number of records */
151 printf("\nFound %d records\n", recordCount);
153 return IX_ETH_DB_SUCCESS;
157 * @brief displays all the filtering records belonging to all the ports
159 * Note that this function is documented in the main component
160 * header file, IxEthDB.h.
162 * @warning deprecated, use @ref ixEthDBFilteringDatabaseShowRecords()
163 * instead. Calling this function is equivalent to calling
164 * ixEthDBFilteringDatabaseShowRecords(IX_ETH_DB_ALL_PORTS, IX_ETH_DB_FILTERING_RECORD)
167 void ixEthDBFilteringDatabaseShowAll()
169 IxEthDBPortId portIndex;
171 printf("\nEthernet learning/filtering database: listing %d ports\n\n", (UINT32) IX_ETH_DB_NUMBER_OF_PORTS);
173 for (portIndex = 0 ; portIndex < IX_ETH_DB_NUMBER_OF_PORTS ; portIndex++)
175 ixEthDBFilteringDatabaseShow(portIndex);
177 if (portIndex < IX_ETH_DB_NUMBER_OF_PORTS - 1)
185 * @brief displays one record in a format depending on the record filter
187 * @param descriptor pointer to the record
188 * @param recordFilter format filter
190 * This function will display the fields in a record depending on the
191 * selected record filter.
196 void ixEthDBRecordShow(MacDescriptor *descriptor, IxEthDBRecordType recordFilter)
198 if (recordFilter == IX_ETH_DB_FILTERING_VLAN_RECORD
199 || recordFilter == (IX_ETH_DB_FILTERING_RECORD | IX_ETH_DB_FILTERING_VLAN_RECORD))
201 /* display VLAN record header - leave this commented code in place, its purpose is to align the print format with the header
202 printf(" MAC address | Age | Type | VLAN ID | CFI | QoS class \n");
203 printf("___________________________________________________________________\n"); */
205 if (descriptor->type == IX_ETH_DB_FILTERING_VLAN_RECORD)
207 printf("%02X:%02X:%02X:%02X:%02X:%02X | %3d | %s | %d | %d | %d\n",
208 descriptor->macAddress[0],
209 descriptor->macAddress[1],
210 descriptor->macAddress[2],
211 descriptor->macAddress[3],
212 descriptor->macAddress[4],
213 descriptor->macAddress[5],
214 descriptor->recordData.filteringVlanData.age,
215 descriptor->recordData.filteringVlanData.staticEntry ? "static" : "dynamic",
216 IX_ETH_DB_GET_VLAN_ID(descriptor->recordData.filteringVlanData.ieee802_1qTag),
217 (descriptor->recordData.filteringVlanData.ieee802_1qTag & 0x1000) >> 12,
218 IX_ETH_DB_GET_QOS_PRIORITY(descriptor->recordData.filteringVlanData.ieee802_1qTag));
220 else if (descriptor->type == IX_ETH_DB_FILTERING_RECORD)
222 printf("%02X:%02X:%02X:%02X:%02X:%02X | %3d | %s | - | - | -\n",
223 descriptor->macAddress[0],
224 descriptor->macAddress[1],
225 descriptor->macAddress[2],
226 descriptor->macAddress[3],
227 descriptor->macAddress[4],
228 descriptor->macAddress[5],
229 descriptor->recordData.filteringData.age,
230 descriptor->recordData.filteringData.staticEntry ? "static" : "dynamic");
233 else if (recordFilter == IX_ETH_DB_FILTERING_RECORD)
235 /* display filtering record header - leave this commented code in place, its purpose is to align the print format with the header
236 printf(" MAC address | Age | Type \n");
237 printf("_______________________________________\n"); */
239 if (descriptor->type == IX_ETH_DB_FILTERING_RECORD)
241 printf("%02X:%02X:%02X:%02X:%02X:%02X | %3d | %s \n",
242 descriptor->macAddress[0],
243 descriptor->macAddress[1],
244 descriptor->macAddress[2],
245 descriptor->macAddress[3],
246 descriptor->macAddress[4],
247 descriptor->macAddress[5],
248 descriptor->recordData.filteringData.age,
249 descriptor->recordData.filteringData.staticEntry ? "static" : "dynamic");
252 else if (recordFilter == IX_ETH_DB_WIFI_RECORD)
254 /* display WiFi record header - leave this commented code in place, its purpose is to align the print format with the header
255 printf(" MAC address | GW MAC address \n");
256 printf("_______________________________________\n"); */
258 if (descriptor->type == IX_ETH_DB_WIFI_RECORD)
260 if (descriptor->recordData.wifiData.type == IX_ETH_DB_WIFI_AP_TO_AP)
262 /* gateway address present */
263 printf("%02X:%02X:%02X:%02X:%02X:%02X | %02X:%02X:%02X:%02X:%02X:%02X \n",
264 descriptor->macAddress[0],
265 descriptor->macAddress[1],
266 descriptor->macAddress[2],
267 descriptor->macAddress[3],
268 descriptor->macAddress[4],
269 descriptor->macAddress[5],
270 descriptor->recordData.wifiData.gwMacAddress[0],
271 descriptor->recordData.wifiData.gwMacAddress[1],
272 descriptor->recordData.wifiData.gwMacAddress[2],
273 descriptor->recordData.wifiData.gwMacAddress[3],
274 descriptor->recordData.wifiData.gwMacAddress[4],
275 descriptor->recordData.wifiData.gwMacAddress[5]);
280 printf("%02X:%02X:%02X:%02X:%02X:%02X | ----no gateway----- \n",
281 descriptor->macAddress[0],
282 descriptor->macAddress[1],
283 descriptor->macAddress[2],
284 descriptor->macAddress[3],
285 descriptor->macAddress[4],
286 descriptor->macAddress[5]);
290 else if (recordFilter == IX_ETH_DB_FIREWALL_RECORD)
292 /* display Firewall record header - leave this commented code in place, its purpose is to align the print format with the header
293 printf(" MAC address \n");
294 printf("__________________\n"); */
296 if (descriptor->type == IX_ETH_DB_FIREWALL_RECORD)
298 printf("%02X:%02X:%02X:%02X:%02X:%02X \n",
299 descriptor->macAddress[0],
300 descriptor->macAddress[1],
301 descriptor->macAddress[2],
302 descriptor->macAddress[3],
303 descriptor->macAddress[4],
304 descriptor->macAddress[5]);
307 else if (recordFilter == IX_ETH_DB_ALL_RECORD_TYPES)
309 /* display composite record header - leave this commented code in place, its purpose is to align the print format with the header
310 printf(" MAC address | Record | Age| Type | VLAN |CFI| QoS | GW MAC address \n");
311 printf("_______________________________________________________________________________\n"); */
313 if (descriptor->type == IX_ETH_DB_FILTERING_VLAN_RECORD)
315 printf("%02X:%02X:%02X:%02X:%02X:%02X | VLAN | %2d | %s | %4d | %1d | %1d | -----------------\n",
316 descriptor->macAddress[0],
317 descriptor->macAddress[1],
318 descriptor->macAddress[2],
319 descriptor->macAddress[3],
320 descriptor->macAddress[4],
321 descriptor->macAddress[5],
322 descriptor->recordData.filteringVlanData.age,
323 descriptor->recordData.filteringVlanData.staticEntry ? "static " : "dynamic",
324 IX_ETH_DB_GET_VLAN_ID(descriptor->recordData.filteringVlanData.ieee802_1qTag),
325 (descriptor->recordData.filteringVlanData.ieee802_1qTag & 0x1000) >> 12,
326 IX_ETH_DB_GET_QOS_PRIORITY(descriptor->recordData.filteringVlanData.ieee802_1qTag));
328 else if (descriptor->type == IX_ETH_DB_FILTERING_RECORD)
330 printf("%02X:%02X:%02X:%02X:%02X:%02X | Filter | %2d | %s | ---- | - | --- | -----------------\n",
331 descriptor->macAddress[0],
332 descriptor->macAddress[1],
333 descriptor->macAddress[2],
334 descriptor->macAddress[3],
335 descriptor->macAddress[4],
336 descriptor->macAddress[5],
337 descriptor->recordData.filteringData.age,
338 descriptor->recordData.filteringData.staticEntry ? "static " : "dynamic");
340 else if (descriptor->type == IX_ETH_DB_WIFI_RECORD)
342 if (descriptor->recordData.wifiData.type == IX_ETH_DB_WIFI_AP_TO_AP)
344 /* gateway address present */
345 printf("%02X:%02X:%02X:%02X:%02X:%02X | WiFi | -- | AP=>AP | ---- | - | --- | %02X:%02X:%02X:%02X:%02X:%02X\n",
346 descriptor->macAddress[0],
347 descriptor->macAddress[1],
348 descriptor->macAddress[2],
349 descriptor->macAddress[3],
350 descriptor->macAddress[4],
351 descriptor->macAddress[5],
352 descriptor->recordData.wifiData.gwMacAddress[0],
353 descriptor->recordData.wifiData.gwMacAddress[1],
354 descriptor->recordData.wifiData.gwMacAddress[2],
355 descriptor->recordData.wifiData.gwMacAddress[3],
356 descriptor->recordData.wifiData.gwMacAddress[4],
357 descriptor->recordData.wifiData.gwMacAddress[5]);
362 printf("%02X:%02X:%02X:%02X:%02X:%02X | WiFi | -- | AP=>ST | ---- | - | --- | -- no gateway -- \n",
363 descriptor->macAddress[0],
364 descriptor->macAddress[1],
365 descriptor->macAddress[2],
366 descriptor->macAddress[3],
367 descriptor->macAddress[4],
368 descriptor->macAddress[5]);
371 else if (descriptor->type == IX_ETH_DB_FIREWALL_RECORD)
373 printf("%02X:%02X:%02X:%02X:%02X:%02X | FW | -- | ------- | ---- | - | --- | -----------------\n",
374 descriptor->macAddress[0],
375 descriptor->macAddress[1],
376 descriptor->macAddress[2],
377 descriptor->macAddress[3],
378 descriptor->macAddress[4],
379 descriptor->macAddress[5]);
384 printf("invalid record filter\n");
389 * @brief displays the status, records and configuration information of a port
391 * @param portID ID of the port
392 * @param recordFilter record filter to display
397 void ixEthDBPortInfoShow(IxEthDBPortId portID, IxEthDBRecordType recordFilter)
399 PortInfo *portInfo = &ixEthDBPortInfo[portID];
400 UINT32 recordCount = 0;
401 HashIterator iterator;
402 IxEthDBStatus local_result;
404 /* display port status */
405 printf("== Port ID %d ==\n", portID);
407 /* display capabilities */
408 printf("- Capabilities: ");
410 if ((portInfo->featureCapability & IX_ETH_DB_LEARNING) != 0)
412 printf("Learning (%s) ", ((portInfo->featureStatus & IX_ETH_DB_LEARNING) != 0) ? "on" : "off");
415 if ((portInfo->featureCapability & IX_ETH_DB_VLAN_QOS) != 0)
417 printf("VLAN/QoS (%s) ", ((portInfo->featureStatus & IX_ETH_DB_VLAN_QOS) != 0) ? "on" : "off");
420 if ((portInfo->featureCapability & IX_ETH_DB_FIREWALL) != 0)
422 printf("Firewall (%s) ", ((portInfo->featureStatus & IX_ETH_DB_FIREWALL) != 0) ? "on" : "off");
425 if ((portInfo->featureCapability & IX_ETH_DB_WIFI_HEADER_CONVERSION) != 0)
427 printf("WiFi (%s) ", ((portInfo->featureStatus & IX_ETH_DB_WIFI_HEADER_CONVERSION) != 0) ? "on" : "off");
430 if ((portInfo->featureCapability & IX_ETH_DB_SPANNING_TREE_PROTOCOL) != 0)
432 printf("STP (%s) ", ((portInfo->featureStatus & IX_ETH_DB_SPANNING_TREE_PROTOCOL) != 0) ? "on" : "off");
438 ixEthDBDependencyPortMapShow(portID, portInfo->dependencyPortMap);
440 /* NPE dynamic updates */
441 if (ixEthDBPortDefinitions[portID].type == IX_ETH_NPE)
443 printf(" - NPE dynamic update is %s\n", portInfo->updateMethod.updateEnabled ? "enabled" : "disabled");
447 printf(" - dynamic update disabled (not an NPE)\n");
450 if ((portInfo->featureCapability & IX_ETH_DB_WIFI_HEADER_CONVERSION) != 0)
452 if ((portInfo->featureStatus & IX_ETH_DB_WIFI_HEADER_CONVERSION) != 0)
454 /* WiFi header conversion */
455 if ((portInfo->frameControlDurationID
461 + portInfo->bbsid[5]) == 0)
463 printf(" - WiFi header conversion not configured\n");
467 printf(" - WiFi header conversion: BBSID [%02X:%02X:%02X:%02X:%02X:%02X], Frame Control 0x%X, Duration/ID 0x%X\n",
474 portInfo->frameControlDurationID >> 16,
475 portInfo->frameControlDurationID & 0xFFFF);
480 printf(" - WiFi header conversion not enabled\n");
485 if ((portInfo->featureCapability & IX_ETH_DB_FIREWALL) != 0)
487 if ((portInfo->featureStatus & IX_ETH_DB_FIREWALL) != 0)
489 printf(" - Firewall is in %s-list mode\n", portInfo->firewallMode == IX_ETH_DB_FIREWALL_BLACK_LIST ? "black" : "white");
490 printf(" - Invalid source MAC address filtering is %s\n", portInfo->srcAddressFilterEnabled ? "enabled" : "disabled");
494 printf(" - Firewall not enabled\n");
498 /* browse database if asked to display records */
499 if (recordFilter != IX_ETH_DB_NO_RECORD_TYPE)
502 ixEthDBHeaderShow(recordFilter);
504 BUSY_RETRY(ixEthDBInitHashIterator(&dbHashtable, &iterator));
506 while (IS_ITERATOR_VALID(&iterator))
508 MacDescriptor *descriptor = (MacDescriptor *) iterator.node->data;
510 if (descriptor->portID == portID && (descriptor->type & recordFilter) != 0)
515 ixEthDBRecordShow(descriptor, recordFilter);
518 /* move to the next record */
519 BUSY_RETRY_WITH_RESULT(ixEthDBIncrementHashIterator(&dbHashtable, &iterator), local_result);
522 if (local_result == IX_ETH_DB_BUSY)
524 printf("EthDB (API): Error, database browser failed (no access), giving up\n");
528 printf("\nFound %d records\n\n", recordCount);
533 * @brief displays a record header
535 * @param recordFilter record type filter
537 * This function displays a record header, depending on
538 * the given record type filter. It is useful when used
539 * in conjunction with ixEthDBRecordShow which will display
540 * record fields formatted for the header, provided the same
541 * record filter is used.
543 * @return IX_ETH_DB_SUCCESS if the operation completed
544 * successfully or IX_ETH_DB_INVALID_ARG if the recordFilter
545 * parameter is invalid or not supported
550 IxEthDBStatus ixEthDBHeaderShow(IxEthDBRecordType recordFilter)
552 if (recordFilter == IX_ETH_DB_FILTERING_VLAN_RECORD
553 || recordFilter == (IX_ETH_DB_FILTERING_RECORD | IX_ETH_DB_FILTERING_VLAN_RECORD))
555 /* display VLAN record header */
556 printf(" MAC address | Age | Type | VLAN ID | CFI | QoS class \n");
557 printf("___________________________________________________________________\n");
559 else if (recordFilter == IX_ETH_DB_FILTERING_RECORD)
561 /* display filtering record header */
562 printf(" MAC address | Age | Type \n");
563 printf("_______________________________________\n");
565 else if (recordFilter == IX_ETH_DB_WIFI_RECORD)
567 /* display WiFi record header */
568 printf(" MAC address | GW MAC address \n");
569 printf("_______________________________________\n");
571 else if (recordFilter == IX_ETH_DB_FIREWALL_RECORD)
573 /* display Firewall record header */
574 printf(" MAC address \n");
575 printf("__________________\n");
577 else if (recordFilter == IX_ETH_DB_ALL_RECORD_TYPES)
579 /* display composite record header */
580 printf(" MAC address | Record | Age| Type | VLAN |CFI| QoS | GW MAC address \n");
581 printf("_______________________________________________________________________________\n");
585 return IX_ETH_DB_INVALID_ARG;
588 return IX_ETH_DB_SUCCESS;
592 * @brief displays database information (records and port information)
594 * @param portID ID of the port to display (or IX_ETH_DB_ALL_PORTS for all the ports)
595 * @param recordFilter record filter (use IX_ETH_DB_NO_RECORD_TYPE to display only
598 * Note that this function is documented in the main component header
601 * @return IX_ETH_DB_SUCCESS if the operation completed successfully or
602 * an appropriate error code otherwise
606 IxEthDBStatus ixEthDBFilteringDatabaseShowRecords(IxEthDBPortId portID, IxEthDBRecordType recordFilter)
608 IxEthDBPortId currentPort;
609 BOOL showAllPorts = (portID == IX_ETH_DB_ALL_PORTS);
611 IX_ETH_DB_CHECK_PORT_ALL(portID);
613 printf("\nEthernet learning/filtering database: listing %d port(s)\n\n", showAllPorts ? (UINT32) IX_ETH_DB_NUMBER_OF_PORTS : 1);
615 currentPort = showAllPorts ? 0 : portID;
617 while (currentPort != IX_ETH_DB_NUMBER_OF_PORTS)
619 /* display port info */
620 ixEthDBPortInfoShow(currentPort, recordFilter);
623 currentPort = showAllPorts ? currentPort + 1 : IX_ETH_DB_NUMBER_OF_PORTS;
626 return IX_ETH_DB_SUCCESS;