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 /* forward prototypes */
25 MacTreeNode *ixEthDBGatewaySelect(MacTreeNode *stations);
28 * @brief sets the BBSID value for the WiFi header conversion feature
30 * @param portID ID of the port
31 * @param bbsid pointer to the 6-byte BBSID value
33 * Note that this function is documented in the main component
34 * header file, IxEthDB.h.
36 * @return IX_ETH_DB_SUCCESS if the operation completed successfully
37 * or an appropriate error message otherwise
40 IxEthDBStatus ixEthDBWiFiBBSIDSet(IxEthDBPortId portID, IxEthDBMacAddr *bbsid)
42 IxNpeMhMessage message;
45 IX_ETH_DB_CHECK_PORT(portID);
47 IX_ETH_DB_CHECK_SINGLE_NPE(portID);
49 IX_ETH_DB_CHECK_FEATURE(portID, IX_ETH_DB_WIFI_HEADER_CONVERSION);
51 IX_ETH_DB_CHECK_REFERENCE(bbsid);
53 memcpy(ixEthDBPortInfo[portID].bbsid, bbsid, sizeof (IxEthDBMacAddr));
55 FILL_SETBBSID_MSG(message, portID, bbsid);
57 IX_ETHDB_SEND_NPE_MSG(IX_ETH_DB_PORT_ID_TO_NPE(portID), message, result);
63 * @brief updates the Frame Control and Duration/ID WiFi header
64 * conversion parameters in an NPE
66 * @param portID ID of the port
68 * This function will send a message to the NPE updating the
69 * frame conversion parameters for 802.3 => 802.11 header conversion.
71 * @return IX_ETH_DB_SUCCESS if the operation completed successfully
72 * or IX_ETH_DB_FAIL otherwise
77 IxEthDBStatus ixEthDBWiFiFrameControlDurationIDUpdate(IxEthDBPortId portID)
79 IxNpeMhMessage message;
82 FILL_SETFRAMECONTROLDURATIONID(message, portID, ixEthDBPortInfo[portID].frameControlDurationID);
84 IX_ETHDB_SEND_NPE_MSG(IX_ETH_DB_PORT_ID_TO_NPE(portID), message, result);
90 * @brief sets the Duration/ID WiFi frame header conversion parameter
92 * @param portID ID of the port
93 * @param durationID 16-bit value containing the new Duration/ID parameter
95 * Note that this function is documented in the main component
96 * header file, IxEthDB.h.
98 * @return IX_ETH_DB_SUCCESS if the operation completed successfully
99 * or an appropriate error message otherwise
102 IxEthDBStatus ixEthDBWiFiDurationIDSet(IxEthDBPortId portID, UINT16 durationID)
104 IX_ETH_DB_CHECK_PORT(portID);
106 IX_ETH_DB_CHECK_SINGLE_NPE(portID);
108 IX_ETH_DB_CHECK_FEATURE(portID, IX_ETH_DB_WIFI_HEADER_CONVERSION);
110 ixEthDBPortInfo[portID].frameControlDurationID = (ixEthDBPortInfo[portID].frameControlDurationID & 0xFFFF0000) | durationID;
112 return ixEthDBWiFiFrameControlDurationIDUpdate(portID);
116 * @brief sets the Frame Control WiFi frame header conversion parameter
118 * @param portID ID of the port
119 * @param durationID 16-bit value containing the new Frame Control parameter
121 * Note that this function is documented in the main component
122 * header file, IxEthDB.h.
124 * @return IX_ETH_DB_SUCCESS if the operation completed successfully
125 * or an appropriate error message otherwise
128 IxEthDBStatus ixEthDBWiFiFrameControlSet(IxEthDBPortId portID, UINT16 frameControl)
130 IX_ETH_DB_CHECK_PORT(portID);
132 IX_ETH_DB_CHECK_SINGLE_NPE(portID);
134 IX_ETH_DB_CHECK_FEATURE(portID, IX_ETH_DB_WIFI_HEADER_CONVERSION);
136 ixEthDBPortInfo[portID].frameControlDurationID = (ixEthDBPortInfo[portID].frameControlDurationID & 0xFFFF) | (frameControl << 16);
138 return ixEthDBWiFiFrameControlDurationIDUpdate(portID);
142 * @brief removes a WiFi header conversion record
144 * @param portID ID of the port
145 * @param macAddr MAC address of the record to remove
147 * Note that this function is documented in the main
148 * component header file, IxEthDB.h.
150 * @return IX_ETH_DB_SUCCESS if the operation completed
151 * successfully or an appropriate error message otherwise
154 IxEthDBStatus ixEthDBWiFiEntryRemove(IxEthDBPortId portID, IxEthDBMacAddr *macAddr)
156 MacDescriptor recordTemplate;
158 IX_ETH_DB_CHECK_PORT(portID);
160 IX_ETH_DB_CHECK_SINGLE_NPE(portID);
162 IX_ETH_DB_CHECK_REFERENCE(macAddr);
164 IX_ETH_DB_CHECK_FEATURE(portID, IX_ETH_DB_WIFI_HEADER_CONVERSION);
166 memcpy(recordTemplate.macAddress, macAddr, sizeof (IxEthDBMacAddr));
168 recordTemplate.type = IX_ETH_DB_WIFI_RECORD;
169 recordTemplate.portID = portID;
171 return ixEthDBRemove(&recordTemplate, NULL);
175 * @brief adds a WiFi header conversion record
177 * @param portID ID of the port
178 * @param macAddr MAC address of the record to add
179 * @param gatewayMacAddr address of the gateway (or
180 * NULL if this is a station record)
182 * This function adds a record of type AP_TO_AP (gateway is not NULL)
183 * or AP_TO_STA (gateway is NULL) in the main database as a
184 * WiFi header conversion record.
186 * @return IX_ETH_DB_SUCCESS if the operation completed
187 * successfully or an appropriate error message otherwise
192 IxEthDBStatus ixEthDBWiFiEntryAdd(IxEthDBPortId portID, IxEthDBMacAddr *macAddr, IxEthDBMacAddr *gatewayMacAddr)
194 MacDescriptor recordTemplate;
196 IX_ETH_DB_CHECK_PORT(portID);
198 IX_ETH_DB_CHECK_SINGLE_NPE(portID);
200 IX_ETH_DB_CHECK_REFERENCE(macAddr);
202 IX_ETH_DB_CHECK_FEATURE(portID, IX_ETH_DB_WIFI_HEADER_CONVERSION);
204 memcpy(recordTemplate.macAddress, macAddr, sizeof (IxEthDBMacAddr));
206 recordTemplate.type = IX_ETH_DB_WIFI_RECORD;
207 recordTemplate.portID = portID;
209 if (gatewayMacAddr != NULL)
211 memcpy(recordTemplate.recordData.wifiData.gwMacAddress, gatewayMacAddr, sizeof (IxEthDBMacAddr));
213 recordTemplate.recordData.wifiData.type = IX_ETH_DB_WIFI_AP_TO_AP;
217 memset(recordTemplate.recordData.wifiData.gwMacAddress, 0, sizeof (IxEthDBMacAddr));
219 recordTemplate.recordData.wifiData.type = IX_ETH_DB_WIFI_AP_TO_STA;
222 return ixEthDBAdd(&recordTemplate, NULL);
226 * @brief adds a WiFi header conversion record
228 * @param portID ID of the port
229 * @param macAddr MAC address of the record to add
230 * @param gatewayMacAddr address of the gateway
232 * This function adds a record of type AP_TO_AP
233 * in the main database as a WiFi header conversion record.
235 * This is simply a wrapper over @ref ixEthDBWiFiEntryAdd().
237 * Note that this function is documented in the main
238 * component header file, IxEthDB.h.
240 * @return IX_ETH_DB_SUCCESS if the operation completed
241 * successfully or an appropriate error message otherwise
244 IxEthDBStatus ixEthDBWiFiAccessPointEntryAdd(IxEthDBPortId portID, IxEthDBMacAddr *macAddr, IxEthDBMacAddr *gatewayMacAddr)
246 IX_ETH_DB_CHECK_REFERENCE(gatewayMacAddr);
248 return ixEthDBWiFiEntryAdd(portID, macAddr, gatewayMacAddr);
252 * @brief adds a WiFi header conversion record
254 * @param portID ID of the port
255 * @param macAddr MAC address of the record to add
257 * This function adds a record of type AP_TO_STA
258 * in the main database as a WiFi header conversion record.
260 * This is simply a wrapper over @ref ixEthDBWiFiEntryAdd().
262 * Note that this function is documented in the main
263 * component header file, IxEthDB.h.
265 * @return IX_ETH_DB_SUCCESS if the operation completed
266 * successfully or an appropriate error message otherwise
269 IxEthDBStatus ixEthDBWiFiStationEntryAdd(IxEthDBPortId portID, IxEthDBMacAddr *macAddr)
271 return ixEthDBWiFiEntryAdd(portID, macAddr, NULL);
275 * @brief selects a set of gateways from a tree of
276 * WiFi header conversion records
278 * @param stations binary tree containing pointers to WiFi header
281 * This function browses through the input binary tree, identifies
282 * records of type AP_TO_AP, clones these records and appends them
283 * to a vine (a single right-branch binary tree) which is returned
284 * as result. A maximum of MAX_GW_SIZE entries containing gateways
285 * will be cloned from the original tree.
287 * @return vine (linear binary tree) containing record
288 * clones of AP_TO_AP type, which have a gateway field
293 MacTreeNode *ixEthDBGatewaySelect(MacTreeNode *stations)
295 MacTreeNodeStack *stack;
296 MacTreeNode *gateways, *insertionPlace;
297 UINT32 gwIndex = 1; /* skip the empty root */
299 if (stations == NULL)
304 stack = ixOsalCacheDmaMalloc(sizeof (MacTreeNodeStack));
308 ERROR_LOG("DB: (WiFi) failed to allocate the node stack for gateway tree linearization, out of memory?\n");
312 /* initialize root node */
313 gateways = insertionPlace = NULL;
315 /* start browsing the station tree */
316 NODE_STACK_INIT(stack);
318 /* initialize stack by pushing the tree root at offset 0 */
319 NODE_STACK_PUSH(stack, stations, 0);
321 while (NODE_STACK_NONEMPTY(stack))
326 NODE_STACK_POP(stack, node, offset);
328 /* we can store maximum 31 (32 total, 1 empty root) entries in the gateway tree */
329 if (offset > (MAX_GW_SIZE - 1)) break;
331 /* check if this record has a gateway address */
332 if (node->descriptor != NULL && node->descriptor->recordData.wifiData.type == IX_ETH_DB_WIFI_AP_TO_AP)
334 /* found a record, create an insertion place */
335 if (insertionPlace != NULL)
337 insertionPlace->right = ixEthDBAllocMacTreeNode();
338 insertionPlace = insertionPlace->right;
342 gateways = ixEthDBAllocMacTreeNode();
343 insertionPlace = gateways;
346 if (insertionPlace == NULL)
348 /* no nodes left, bail out with what we have */
349 ixOsalCacheDmaFree(stack);
353 /* clone the original record for the gateway tree */
354 insertionPlace->descriptor = ixEthDBCloneMacDescriptor(node->descriptor);
356 /* insert and update the offset in the original record */
357 node->descriptor->recordData.wifiData.gwAddressIndex = gwIndex++;
360 /* browse the tree */
361 if (node->left != NULL)
363 NODE_STACK_PUSH(stack, node->left, LEFT_CHILD_OFFSET(offset));
366 if (node->right != NULL)
368 NODE_STACK_PUSH(stack, node->right, RIGHT_CHILD_OFFSET(offset));
372 ixOsalCacheDmaFree(stack);
377 * @brief downloads the WiFi header conversion table to an NPE
379 * @param portID ID of the port
381 * This function prepares the WiFi header conversion tables and
382 * downloads them to the specified NPE port.
384 * The header conversion tables consist in the main table of
385 * addresses and the secondary table of gateways. AP_TO_AP records
386 * from the first table contain index fields into the second table
387 * for gateway selection.
389 * Note that this function is documented in the main component
390 * header file, IxEthDB.h.
392 * @return IX_ETH_DB_SUCCESS if the operation completed successfully
393 * or an appropriate error message otherwise
396 IxEthDBStatus ixEthDBWiFiConversionTableDownload(IxEthDBPortId portID)
398 IxEthDBPortMap query;
399 MacTreeNode *stations = NULL, *gateways = NULL, *gateway = NULL;
400 IxNpeMhMessage message;
404 IX_ETH_DB_CHECK_PORT(portID);
406 IX_ETH_DB_CHECK_SINGLE_NPE(portID);
408 IX_ETH_DB_CHECK_FEATURE(portID, IX_ETH_DB_WIFI_HEADER_CONVERSION);
410 portInfo = &ixEthDBPortInfo[portID];
412 SET_DEPENDENCY_MAP(query, portID);
416 stations = ixEthDBQuery(NULL, query, IX_ETH_DB_WIFI_RECORD, MAX_ELT_SIZE);
417 gateways = ixEthDBGatewaySelect(stations);
419 /* clean up gw area */
420 memset((void *) portInfo->updateMethod.npeGwUpdateZone, FULL_GW_BYTE_SIZE, 0);
422 /* write all gateways */
425 while (gateway != NULL)
427 ixEthDBNPEGatewayNodeWrite((void *) (((UINT32) portInfo->updateMethod.npeGwUpdateZone)
428 + gateway->descriptor->recordData.wifiData.gwAddressIndex * ELT_ENTRY_SIZE),
431 gateway = gateway->right;
434 /* free the gateway tree */
435 if (gateways != NULL)
437 ixEthDBFreeMacTreeNode(gateways);
440 FILL_SETAPMACTABLE_MSG(message,
441 IX_OSAL_MMU_VIRT_TO_PHYS(portInfo->updateMethod.npeGwUpdateZone));
443 IX_ETHDB_SEND_NPE_MSG(IX_ETH_DB_PORT_ID_TO_NPE(portID), message, result);
445 if (result == IX_SUCCESS)
447 /* update the main tree (the stations tree) */
448 portInfo->updateMethod.searchTree = stations;
450 result = ixEthDBNPEUpdateHandler(portID, IX_ETH_DB_WIFI_RECORD);
453 ixEthDBUpdateUnlock();