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 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. Neither the name of the Intel Corporation nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
30 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * -- End of Copyright Notice --
45 #include "IxEthDB_p.h"
47 /* forward prototypes */
49 MacTreeNode
*ixEthDBGatewaySelect(MacTreeNode
*stations
);
52 * @brief sets the BBSID value for the WiFi header conversion feature
54 * @param portID ID of the port
55 * @param bbsid pointer to the 6-byte BBSID value
57 * Note that this function is documented in the main component
58 * header file, IxEthDB.h.
60 * @return IX_ETH_DB_SUCCESS if the operation completed successfully
61 * or an appropriate error message otherwise
64 IxEthDBStatus
ixEthDBWiFiBBSIDSet(IxEthDBPortId portID
, IxEthDBMacAddr
*bbsid
)
66 IxNpeMhMessage message
;
69 IX_ETH_DB_CHECK_PORT(portID
);
71 IX_ETH_DB_CHECK_SINGLE_NPE(portID
);
73 IX_ETH_DB_CHECK_FEATURE(portID
, IX_ETH_DB_WIFI_HEADER_CONVERSION
);
75 IX_ETH_DB_CHECK_REFERENCE(bbsid
);
77 memcpy(ixEthDBPortInfo
[portID
].bbsid
, bbsid
, sizeof (IxEthDBMacAddr
));
79 FILL_SETBBSID_MSG(message
, portID
, bbsid
);
81 IX_ETHDB_SEND_NPE_MSG(IX_ETH_DB_PORT_ID_TO_NPE(portID
), message
, result
);
87 * @brief updates the Frame Control and Duration/ID WiFi header
88 * conversion parameters in an NPE
90 * @param portID ID of the port
92 * This function will send a message to the NPE updating the
93 * frame conversion parameters for 802.3 => 802.11 header conversion.
95 * @return IX_ETH_DB_SUCCESS if the operation completed successfully
96 * or IX_ETH_DB_FAIL otherwise
101 IxEthDBStatus
ixEthDBWiFiFrameControlDurationIDUpdate(IxEthDBPortId portID
)
103 IxNpeMhMessage message
;
106 FILL_SETFRAMECONTROLDURATIONID(message
, portID
, ixEthDBPortInfo
[portID
].frameControlDurationID
);
108 IX_ETHDB_SEND_NPE_MSG(IX_ETH_DB_PORT_ID_TO_NPE(portID
), message
, result
);
114 * @brief sets the Duration/ID WiFi frame header conversion parameter
116 * @param portID ID of the port
117 * @param durationID 16-bit value containing the new Duration/ID parameter
119 * Note that this function is documented in the main component
120 * header file, IxEthDB.h.
122 * @return IX_ETH_DB_SUCCESS if the operation completed successfully
123 * or an appropriate error message otherwise
126 IxEthDBStatus
ixEthDBWiFiDurationIDSet(IxEthDBPortId portID
, UINT16 durationID
)
128 IX_ETH_DB_CHECK_PORT(portID
);
130 IX_ETH_DB_CHECK_SINGLE_NPE(portID
);
132 IX_ETH_DB_CHECK_FEATURE(portID
, IX_ETH_DB_WIFI_HEADER_CONVERSION
);
134 ixEthDBPortInfo
[portID
].frameControlDurationID
= (ixEthDBPortInfo
[portID
].frameControlDurationID
& 0xFFFF0000) | durationID
;
136 return ixEthDBWiFiFrameControlDurationIDUpdate(portID
);
140 * @brief sets the Frame Control WiFi frame header conversion parameter
142 * @param portID ID of the port
143 * @param durationID 16-bit value containing the new Frame Control parameter
145 * Note that this function is documented in the main component
146 * header file, IxEthDB.h.
148 * @return IX_ETH_DB_SUCCESS if the operation completed successfully
149 * or an appropriate error message otherwise
152 IxEthDBStatus
ixEthDBWiFiFrameControlSet(IxEthDBPortId portID
, UINT16 frameControl
)
154 IX_ETH_DB_CHECK_PORT(portID
);
156 IX_ETH_DB_CHECK_SINGLE_NPE(portID
);
158 IX_ETH_DB_CHECK_FEATURE(portID
, IX_ETH_DB_WIFI_HEADER_CONVERSION
);
160 ixEthDBPortInfo
[portID
].frameControlDurationID
= (ixEthDBPortInfo
[portID
].frameControlDurationID
& 0xFFFF) | (frameControl
<< 16);
162 return ixEthDBWiFiFrameControlDurationIDUpdate(portID
);
166 * @brief removes a WiFi header conversion record
168 * @param portID ID of the port
169 * @param macAddr MAC address of the record to remove
171 * Note that this function is documented in the main
172 * component header file, IxEthDB.h.
174 * @return IX_ETH_DB_SUCCESS if the operation completed
175 * successfully or an appropriate error message otherwise
178 IxEthDBStatus
ixEthDBWiFiEntryRemove(IxEthDBPortId portID
, IxEthDBMacAddr
*macAddr
)
180 MacDescriptor recordTemplate
;
182 IX_ETH_DB_CHECK_PORT(portID
);
184 IX_ETH_DB_CHECK_SINGLE_NPE(portID
);
186 IX_ETH_DB_CHECK_REFERENCE(macAddr
);
188 IX_ETH_DB_CHECK_FEATURE(portID
, IX_ETH_DB_WIFI_HEADER_CONVERSION
);
190 memcpy(recordTemplate
.macAddress
, macAddr
, sizeof (IxEthDBMacAddr
));
192 recordTemplate
.type
= IX_ETH_DB_WIFI_RECORD
;
193 recordTemplate
.portID
= portID
;
195 return ixEthDBRemove(&recordTemplate
, NULL
);
199 * @brief adds a WiFi header conversion record
201 * @param portID ID of the port
202 * @param macAddr MAC address of the record to add
203 * @param gatewayMacAddr address of the gateway (or
204 * NULL if this is a station record)
206 * This function adds a record of type AP_TO_AP (gateway is not NULL)
207 * or AP_TO_STA (gateway is NULL) in the main database as a
208 * WiFi header conversion record.
210 * @return IX_ETH_DB_SUCCESS if the operation completed
211 * successfully or an appropriate error message otherwise
216 IxEthDBStatus
ixEthDBWiFiEntryAdd(IxEthDBPortId portID
, IxEthDBMacAddr
*macAddr
, IxEthDBMacAddr
*gatewayMacAddr
)
218 MacDescriptor recordTemplate
;
220 IX_ETH_DB_CHECK_PORT(portID
);
222 IX_ETH_DB_CHECK_SINGLE_NPE(portID
);
224 IX_ETH_DB_CHECK_REFERENCE(macAddr
);
226 IX_ETH_DB_CHECK_FEATURE(portID
, IX_ETH_DB_WIFI_HEADER_CONVERSION
);
228 memcpy(recordTemplate
.macAddress
, macAddr
, sizeof (IxEthDBMacAddr
));
230 recordTemplate
.type
= IX_ETH_DB_WIFI_RECORD
;
231 recordTemplate
.portID
= portID
;
233 if (gatewayMacAddr
!= NULL
)
235 memcpy(recordTemplate
.recordData
.wifiData
.gwMacAddress
, gatewayMacAddr
, sizeof (IxEthDBMacAddr
));
237 recordTemplate
.recordData
.wifiData
.type
= IX_ETH_DB_WIFI_AP_TO_AP
;
241 memset(recordTemplate
.recordData
.wifiData
.gwMacAddress
, 0, sizeof (IxEthDBMacAddr
));
243 recordTemplate
.recordData
.wifiData
.type
= IX_ETH_DB_WIFI_AP_TO_STA
;
246 return ixEthDBAdd(&recordTemplate
, NULL
);
250 * @brief adds a WiFi header conversion record
252 * @param portID ID of the port
253 * @param macAddr MAC address of the record to add
254 * @param gatewayMacAddr address of the gateway
256 * This function adds a record of type AP_TO_AP
257 * in the main database as a WiFi header conversion record.
259 * This is simply a wrapper over @ref ixEthDBWiFiEntryAdd().
261 * Note that this function is documented in the main
262 * component header file, IxEthDB.h.
264 * @return IX_ETH_DB_SUCCESS if the operation completed
265 * successfully or an appropriate error message otherwise
268 IxEthDBStatus
ixEthDBWiFiAccessPointEntryAdd(IxEthDBPortId portID
, IxEthDBMacAddr
*macAddr
, IxEthDBMacAddr
*gatewayMacAddr
)
270 IX_ETH_DB_CHECK_REFERENCE(gatewayMacAddr
);
272 return ixEthDBWiFiEntryAdd(portID
, macAddr
, gatewayMacAddr
);
276 * @brief adds a WiFi header conversion record
278 * @param portID ID of the port
279 * @param macAddr MAC address of the record to add
281 * This function adds a record of type AP_TO_STA
282 * in the main database as a WiFi header conversion record.
284 * This is simply a wrapper over @ref ixEthDBWiFiEntryAdd().
286 * Note that this function is documented in the main
287 * component header file, IxEthDB.h.
289 * @return IX_ETH_DB_SUCCESS if the operation completed
290 * successfully or an appropriate error message otherwise
293 IxEthDBStatus
ixEthDBWiFiStationEntryAdd(IxEthDBPortId portID
, IxEthDBMacAddr
*macAddr
)
295 return ixEthDBWiFiEntryAdd(portID
, macAddr
, NULL
);
299 * @brief selects a set of gateways from a tree of
300 * WiFi header conversion records
302 * @param stations binary tree containing pointers to WiFi header
305 * This function browses through the input binary tree, identifies
306 * records of type AP_TO_AP, clones these records and appends them
307 * to a vine (a single right-branch binary tree) which is returned
308 * as result. A maximum of MAX_GW_SIZE entries containing gateways
309 * will be cloned from the original tree.
311 * @return vine (linear binary tree) containing record
312 * clones of AP_TO_AP type, which have a gateway field
317 MacTreeNode
*ixEthDBGatewaySelect(MacTreeNode
*stations
)
319 MacTreeNodeStack
*stack
;
320 MacTreeNode
*gateways
, *insertionPlace
;
321 UINT32 gwIndex
= 1; /* skip the empty root */
323 if (stations
== NULL
)
328 stack
= ixOsalCacheDmaMalloc(sizeof (MacTreeNodeStack
));
332 ERROR_LOG("DB: (WiFi) failed to allocate the node stack for gateway tree linearization, out of memory?\n");
336 /* initialize root node */
337 gateways
= insertionPlace
= NULL
;
339 /* start browsing the station tree */
340 NODE_STACK_INIT(stack
);
342 /* initialize stack by pushing the tree root at offset 0 */
343 NODE_STACK_PUSH(stack
, stations
, 0);
345 while (NODE_STACK_NONEMPTY(stack
))
350 NODE_STACK_POP(stack
, node
, offset
);
352 /* we can store maximum 31 (32 total, 1 empty root) entries in the gateway tree */
353 if (offset
> (MAX_GW_SIZE
- 1)) break;
355 /* check if this record has a gateway address */
356 if (node
->descriptor
!= NULL
&& node
->descriptor
->recordData
.wifiData
.type
== IX_ETH_DB_WIFI_AP_TO_AP
)
358 /* found a record, create an insertion place */
359 if (insertionPlace
!= NULL
)
361 insertionPlace
->right
= ixEthDBAllocMacTreeNode();
362 insertionPlace
= insertionPlace
->right
;
366 gateways
= ixEthDBAllocMacTreeNode();
367 insertionPlace
= gateways
;
370 if (insertionPlace
== NULL
)
372 /* no nodes left, bail out with what we have */
373 ixOsalCacheDmaFree(stack
);
377 /* clone the original record for the gateway tree */
378 insertionPlace
->descriptor
= ixEthDBCloneMacDescriptor(node
->descriptor
);
380 /* insert and update the offset in the original record */
381 node
->descriptor
->recordData
.wifiData
.gwAddressIndex
= gwIndex
++;
384 /* browse the tree */
385 if (node
->left
!= NULL
)
387 NODE_STACK_PUSH(stack
, node
->left
, LEFT_CHILD_OFFSET(offset
));
390 if (node
->right
!= NULL
)
392 NODE_STACK_PUSH(stack
, node
->right
, RIGHT_CHILD_OFFSET(offset
));
396 ixOsalCacheDmaFree(stack
);
401 * @brief downloads the WiFi header conversion table to an NPE
403 * @param portID ID of the port
405 * This function prepares the WiFi header conversion tables and
406 * downloads them to the specified NPE port.
408 * The header conversion tables consist in the main table of
409 * addresses and the secondary table of gateways. AP_TO_AP records
410 * from the first table contain index fields into the second table
411 * for gateway selection.
413 * Note that this function is documented in the main component
414 * header file, IxEthDB.h.
416 * @return IX_ETH_DB_SUCCESS if the operation completed successfully
417 * or an appropriate error message otherwise
420 IxEthDBStatus
ixEthDBWiFiConversionTableDownload(IxEthDBPortId portID
)
422 IxEthDBPortMap query
;
423 MacTreeNode
*stations
= NULL
, *gateways
= NULL
, *gateway
= NULL
;
424 IxNpeMhMessage message
;
428 IX_ETH_DB_CHECK_PORT(portID
);
430 IX_ETH_DB_CHECK_SINGLE_NPE(portID
);
432 IX_ETH_DB_CHECK_FEATURE(portID
, IX_ETH_DB_WIFI_HEADER_CONVERSION
);
434 portInfo
= &ixEthDBPortInfo
[portID
];
436 SET_DEPENDENCY_MAP(query
, portID
);
440 stations
= ixEthDBQuery(NULL
, query
, IX_ETH_DB_WIFI_RECORD
, MAX_ELT_SIZE
);
441 gateways
= ixEthDBGatewaySelect(stations
);
443 /* clean up gw area */
444 memset((void *) portInfo
->updateMethod
.npeGwUpdateZone
, FULL_GW_BYTE_SIZE
, 0);
446 /* write all gateways */
449 while (gateway
!= NULL
)
451 ixEthDBNPEGatewayNodeWrite((void *) (((UINT32
) portInfo
->updateMethod
.npeGwUpdateZone
)
452 + gateway
->descriptor
->recordData
.wifiData
.gwAddressIndex
* ELT_ENTRY_SIZE
),
455 gateway
= gateway
->right
;
458 /* free the gateway tree */
459 if (gateways
!= NULL
)
461 ixEthDBFreeMacTreeNode(gateways
);
464 FILL_SETAPMACTABLE_MSG(message
,
465 IX_OSAL_MMU_VIRT_TO_PHYS(portInfo
->updateMethod
.npeGwUpdateZone
));
467 IX_ETHDB_SEND_NPE_MSG(IX_ETH_DB_PORT_ID_TO_NPE(portID
), message
, result
);
469 if (result
== IX_SUCCESS
)
471 /* update the main tree (the stations tree) */
472 portInfo
->updateMethod
.searchTree
= stations
;
474 result
= ixEthDBNPEUpdateHandler(portID
, IX_ETH_DB_WIFI_RECORD
);
477 ixEthDBUpdateUnlock();