Integrator Resources

The official home for NAI Support

Not sure where to start? Try Quick Start Guide or ask a question below!

Toggle Components with Visual Button
JavaScript Form Processing

ESW Config

ESW Config Sample Application (SSK 1.x)

Overview

The ESW Config sample application demonstrates how to configure an NAI Ethernet Switch (ESW) module using the NAI Software Support Kit (SSK 1.x). The H2 module is a managed 12-port Ethernet switch that sits on the NAI backplane, routing traffic between module slots, the host processor, and external Ethernet connections. Proper configuration of port link parameters and VLAN segmentation is essential for controlling traffic flow, isolating network domains, and meeting system bandwidth and security requirements.

This sample covers two major areas of switch configuration: port-level link settings (duplex mode, link speed, and gigabit capability advertisement) and VLAN group management (VLAN IDs, membership, packet tagging, IP addressing, and subnet masking). It serves as a practical API reference — each menu command maps directly to one or more naibrd_ESW_*() API calls that you can lift into your own code.

Prerequisites

Before running this sample, make sure you have:

  • An NAI board with an H2 (12-port Ethernet Switch) module installed.

  • SSK 1.x installed on your development host.

  • The sample applications built. Refer to the SSK 1.x build instructions for your platform if you have not already compiled them.

How to Run

Launch the ESW_Config executable from your build output directory. On startup the application looks for a configuration file (default_ESW_Configuration.txt). On the first run, this file will not exist — the application will present an interactive board menu where you configure a board connection, card index, and module slot. You can save this configuration so that subsequent runs skip the menu and connect automatically. Once connected, a top-level command menu lets you choose between port configuration and VLAN configuration.

Board Connection and Module Selection

Note
This startup sequence is common to all NAI sample applications. The board connection and module selection code shown here is not specific to ESW. For details on board connection configuration, see the First Time Setup Guide.

The main() function follows a standard SSK 1.x startup flow:

  1. Call naiapp_RunBoardMenu() to load a saved configuration file (if one exists) or present the interactive board menu. The configuration file (default_ESW_Configuration.txt) is not included with the SSK — it is created when the user saves their connection settings from the board menu. On the first run, the menu will always appear.

  2. Query the user for a card index with naiapp_query_CardIndex().

  3. Query for a module slot with naiapp_query_ModuleNumber().

  4. Pass the card index and module number into Run_ESW_Config(), which retrieves the port count and board generation before entering the command loop.

#if defined (__VXWORKS__)
int32_t ESW_Config(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = FALSE;
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
   {
      while (stop != TRUE)
      {
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         if (stop != TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != TRUE)
            {
               Run_ESW_Config(cardIndex, module);
            }
         }

         printf("\nType Q to quit or Enter key to restart application:\n");
         stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      }
   }

   naiapp_access_CloseAllOpenCards();
   return 0;
}
Important

Common connection errors you may encounter at this stage:

  • No board found — verify that the board is powered on and physically connected. Check that the configuration file lists the correct interface and address.

  • Connection timeout — confirm network settings (for Ethernet connections) or bus configuration (for PCI/PCIe). Firewalls and IP mismatches are frequent causes.

  • Invalid card or module index — indices are zero-based for cards and one-based for modules. Ensure the values you pass match your hardware setup.

  • Module not present at selected slot — the slot you selected does not contain an ESW module. Use the board menu to verify which slots are populated.

Program Structure

Application Parameters

Once connected, Run_ESW_Config() populates an naiapp_AppParameters_t struct that carries the card index, module number, and maximum port count through all command handlers. Your application will need to track the same values:

  • cardIndex — zero-based index of the NAI board.

  • module — one-based module slot containing the H2 ESW module.

  • channel — used to store g_MaxESWPorts, the port count returned by naibrd_ESW_GetPortCount().

The function also calls naibrd_GetBoardGen() to retrieve the board generation, which may affect available features.

naiapp_AppParameters_t  esw_params;
p_naiapp_AppParameters_t esw_config_params = &esw_params;
esw_config_params->cardIndex = cardIndex;
esw_config_params->module = module;

g_MaxESWPorts = naibrd_ESW_GetPortCount( cardIndex, module );
esw_config_params->channel = g_MaxESWPorts;

naibrd_GetBoardGen( cardIndex, &generation );

Command Loop and Menu System

The application uses a two-level menu system. The top-level menu offers two sub-menus:

  • PORT — ESW Port Configuration Functions

  • VLAN — ESW VLAN Configuration Functions

Each sub-menu presents its own set of commands. The menu system is a sample convenience — in your own code, call these API functions directly.

Port Configuration

The Port Configuration sub-menu lets you configure link-level parameters for each of the 12 Ethernet switch ports. When you enter this sub-menu, the application displays a status table showing the current link status, duplex mode, speed, gigabit advertisement, MDI/MDIX mode, and BIT status for every port on the module.

To configure the duplex mode of a specific port, call naibrd_ESW_SetLinkDuplex(). The duplex mode controls whether the port communicates in half-duplex (one direction at a time) or full-duplex (simultaneous bidirectional traffic).

bQuit = GetPortNumber( cardIndex, module, g_MaxESWPorts, DEF_ESW_PORT, &port );
if (!bQuit)
{
   /* duplex: NAI_ESW_LINK_HALF_DUPLEX (0) or NAI_ESW_LINK_FULL_DUPLEX (1) */
   check_status( naibrd_ESW_SetLinkDuplex( cardIndex, module, port, duplex ) );
}

API parameters:

  • cardIndex — zero-based board index.

  • module — one-based module slot.

  • port — one-based port number (1 through 12 on the H2).

  • duplex — NAI_ESW_LINK_HALF_DUPLEX (0x0) for half-duplex, NAI_ESW_LINK_FULL_DUPLEX (0x1) for full-duplex.

To configure the link speed of a specific port, call naibrd_ESW_SetLinkSpeed(). This controls the negotiated or forced Ethernet speed on the port.

bQuit = GetPortNumber( cardIndex, module, g_MaxESWPorts, DEF_ESW_PORT, &port );
if (!bQuit)
{
   /* speed: 0=Auto, 1=10Mbps, 2=100Mbps, 3=1Gbps, 0xF=Disable */
   check_status( naibrd_ESW_SetLinkSpeed( cardIndex, module, port, speed ) );
}

API parameters:

  • port — one-based port number.

  • speed — one of:

    • NAI_ESW_LINK_SPEED_AUTO (0x0) — auto-negotiate speed.

    • NAI_ESW_LINK_SPEED_10 (0x1) — force 10 Mbps.

    • NAI_ESW_LINK_SPEED_100 (0x2) — force 100 Mbps.

    • NAI_ESW_LINK_SPEED_1G (0x3) — force 1 Gbps.

    • NAI_ESW_LINK_SPEED_DISABLE (0xF) — disable the port.

Set Gigabit Capability Advertisement (GIGABIT)

To control whether a port advertises gigabit capability during auto-negotiation, call naibrd_ESW_SetLinkGigCapAdv(). When gigabit advertisement is off, the port will not negotiate above 100 Mbps even if the link partner supports gigabit.

bQuit = GetPortNumber( cardIndex, module, g_MaxESWPorts, DEF_ESW_PORT, &port );
if (!bQuit)
{
   /* linkGigAdv: NAI_ESW_LINK_GIG_ADV_OFF (0) or NAI_ESW_LINK_GIG_ADV_ON (1) */
   check_status( naibrd_ESW_SetLinkGigCapAdv( cardIndex, module, port, linkGigAdv ) );
}

API parameters:

  • port — one-based port number.

  • linkGigAdv — NAI_ESW_LINK_GIG_ADV_OFF (0x0) to suppress gigabit advertisement, NAI_ESW_LINK_GIG_ADV_ON (0x1) to enable it.

Set Raw Duplex Word (RDUPLEX)

To set the duplex mode for all ports in a single register write, call naibrd_ESW_SetLinkDuplexWord(). Each bit in the word corresponds to one port (bit 0 = port 1, bit 1 = port 2, and so on). A bit value of 1 means full-duplex; 0 means half-duplex.

duplexWord = strtol( (const char *)inputBuffer, NULL, 16 );
check_status( naibrd_ESW_SetLinkDuplexWord( cardIndex, module, duplexWord ) );

API parameters:

  • duplexWord — a hexadecimal bitmask where each bit maps to one port’s duplex setting.

Set Raw Speed Word (RSPEED)

To set the link speed for a group of four ports in a single register write, call naibrd_ESW_SetLinkSpeedWord(). The H2’s 12 ports are divided into three groups of four: group 1 covers ports 1-4, group 2 covers ports 5-8, and group 3 covers ports 9-12. Each port’s speed occupies a nibble within the 16-bit word.

/* group: 1 for ports 1-4, 2 for ports 5-8, 3 for ports 9-12 */
speedWord = strtol( (const char *)inputBuffer, NULL, 16 );
check_status( naibrd_ESW_SetLinkSpeedWord( cardIndex, module, group, speedWord ) );

API parameters:

  • group — port group number (1, 2, or 3).

  • speedWord — a hexadecimal value encoding the speed for four ports within the group.

Set Raw Gigabit Capability Word (RGIGABIT)

To set the gigabit capability advertisement state for all ports in a single register write, call naibrd_ESW_SetLinkGigCapAdvWord(). Each bit corresponds to one port.

gigabitWord = strtol( (const char *)inputBuffer, NULL, 16 );
check_status( naibrd_ESW_SetLinkGigCapAdvWord( cardIndex, module, gigabitWord ) );

API parameters:

  • gigabitWord — a hexadecimal bitmask where each bit maps to one port’s gigabit advertisement state.

Important

Common Errors

  • Invalid port number — port numbers are one-based (1 through 12 on the H2). Passing zero or a value greater than the port count will produce an error.

  • Link remains DOWN after configuration — changing duplex or speed settings does not guarantee link establishment. Verify that the link partner is connected, powered, and configured for a compatible speed and duplex mode.

  • Speed mismatch — forcing a specific speed on one end while the partner auto-negotiates can cause duplex mismatches. Either force both ends to the same settings or use auto-negotiation on both.

VLAN Configuration

The VLAN Configuration sub-menu lets you create and manage VLAN groups on the Ethernet switch. VLANs segment network traffic so that ports in one VLAN cannot communicate directly with ports in another VLAN, providing isolation and security. The H2 module supports multiple VLAN groups, each with its own ID, member ports, tagging policy, and optional subnet-based addressing.

When you enter this sub-menu, the application displays a status table showing the current VLAN configuration for every group, including VLAN ID, return status, enable state, type, confirm flag, control register value, members bitmask, tagging bitmask, IPv4/IPv6 address, and network mask.

Set VLAN ID (ID)

To assign a VLAN identifier to a group, call naibrd_ESW_SetVLANID(). The VLAN ID is the 802.1Q tag value that will be used for this group’s traffic.

bQuit = GetVLANGroupNumber( cardIndex, module, maxGroup, DEF_ESW_VLAN_GROUP, &vlan );
if (!bQuit)
{
   vlanid = strtol( (const char *)inputBuffer, NULL, 16 );
   check_status( naibrd_ESW_SetVLANID( cardIndex, module, vlan, vlanid ) );
}

API parameters:

  • vlan — one-based VLAN group number.

  • groupID — the VLAN ID value (hexadecimal). Each group must have a unique ID; the module will reject duplicate IDs.

Clear VLAN Return Status (CLEAR)

To clear the return status register for a specific VLAN group, call naibrd_ESW_ClearVLANReturnStatus(). The return status indicates the result of the most recent VLAN configuration operation on that group. Clearing it resets the status to NAI_ESW_VLAN_RESET (0x0000) so you can track the outcome of the next configuration change.

bQuit = GetVLANGroupNumber( cardIndex, module, maxGroup, DEF_ESW_VLAN_GROUP, &vlan );
if (!bQuit)
{
   check_status( naibrd_ESW_ClearVLANReturnStatus( cardIndex, module, vlan ) );
}

VLAN return status codes (defined in naibrd_esw.h):

  • NAI_ESW_VLAN_RESET (0x0000) — status has been cleared.

  • NAI_ESW_VLAN_CFG_PROCESSING (0x0001) — configuration is being applied.

  • NAI_ESW_VLAN_GROUP_ENABLED (0x0002) — group was successfully enabled.

  • NAI_ESW_VLAN_GROUP_DISABLED (0x0003) — group was successfully disabled.

  • NAI_ESW_VLAN_CFG_FAILED_ID_TAKEN (0x0004) — the requested VLAN ID is already assigned to another group.

  • NAI_ESW_VLAN_CFG_FAILED_ID_ILLEGAL (0x0005) — the requested VLAN ID is not valid.

  • NAI_ESW_VLAN_CFG_MODIFYING_DISABLED_VLAN (0x0006) — you are modifying a VLAN group that is currently disabled.

  • NAI_ESW_VLAN_CFG_GENERAL_FAILURE (0x0007) — a general configuration failure occurred.

Clear All VLAN Return Statuses (GROUP CLEAR)

To clear the return status for every VLAN group on the module in one operation, the sample iterates through all groups and calls naibrd_ESW_ClearVLANReturnStatus() for each one.

int32_t numVLANGroups = naibrd_ESW_GetVLANCount( cardIndex, module );
for ( vlan = 1; vlan <= numVLANGroups; vlan++ )
{
   check_status( naibrd_ESW_ClearVLANReturnStatus( cardIndex, module, vlan ) );
}

There is no single API call to clear all groups at once. In your own application, use the same loop pattern.

Enable or Disable a VLAN (ENABLE)

To enable or disable a VLAN group, call naibrd_ESW_SetVLANControlEnable(). A VLAN group must be enabled before its configuration takes effect on the switch.

bQuit = GetVLANGroupNumber( cardIndex, module, maxGroup, DEF_ESW_VLAN_GROUP, &vlan );
if (!bQuit)
{
   /* vlanEnable: TRUE (1) to enable, FALSE (0) to disable */
   check_status( naibrd_ESW_SetVLANControlEnable( cardIndex, module, vlan, vlanEnable ) );
}

API parameters:

  • vlan — one-based VLAN group number.

  • enable — TRUE to enable the VLAN group, FALSE to disable it.

Set VLAN Type (TYPE)

To set the VLAN segmentation type for a group, call naibrd_ESW_SetVLANControlType(). Port-based VLANs segment traffic by physical port membership. Subnet-based VLANs segment traffic by IP subnet, using the VLAN group’s IP address and network mask.

bQuit = GetVLANGroupNumber( cardIndex, module, maxGroup, DEF_ESW_VLAN_GROUP, &vlan );
if (!bQuit)
{
   /* vlanType: NAI_ESW_VLAN_TYPE_PORT_BASED (0) or NAI_ESW_VLAN_TYPE_SUBNET_BASED (1) */
   check_status( naibrd_ESW_SetVLANControlType( cardIndex, module, vlan, vlanType ) );
}

API parameters:

  • vlan — one-based VLAN group number.

  • vlanType — NAI_ESW_VLAN_TYPE_PORT_BASED (0x0) or NAI_ESW_VLAN_TYPE_SUBNET_BASED (0x1).

Set VLAN Confirm Flag (VLAN CONFIRM)

To trigger the switch to apply the current VLAN group configuration, call naibrd_ESW_SetVLANControlConfirm(). After you have configured a group’s ID, members, type, and other settings, set the confirm flag to initiate the configuration on the hardware. Check the VLAN return status afterward to verify success.

bQuit = GetVLANGroupNumber( cardIndex, module, maxGroup, DEF_ESW_VLAN_GROUP, &vlan );
if (!bQuit)
{
   /* confirm: TRUE (1) to confirm, FALSE (0) to clear */
   check_status( naibrd_ESW_SetVLANControlConfirm( cardIndex, module, vlan, confirm ) );
}

API parameters:

  • vlan — one-based VLAN group number.

  • confirm — TRUE to confirm (apply) the VLAN configuration, FALSE to clear the confirm flag.

Set Raw VLAN Control Word (RAW CTRL)

To set the entire VLAN control register in a single write, call naibrd_ESW_SetVLANControlWord(). The control word combines the enable, type, and confirm fields into one register value. This is useful when you want to set all three fields atomically.

bQuit = GetVLANGroupNumber( cardIndex, module, maxGroup, DEF_ESW_VLAN_GROUP, &vlan );
if (!bQuit)
{
   control = strtol( (const char *)inputBuffer, NULL, 16 );
   check_status( naibrd_ESW_SetVLANControlWord( cardIndex, module, vlan, control ) );
}

Control word bit fields (defined in naibrd_esw.h):

  • Bit 0 (NAI_ESW_VLAN_CTRL_ENABLE, 0x0001) — VLAN enable.

  • Bit 1 (NAI_ESW_VLAN_CTRL_SUBNET_BASED, 0x0002) — subnet-based type (0 = port-based).

  • Bit 15 (NAI_ESW_VLAN_CTRL_CFG_INITIATE, 0x8000) — configuration initiate (confirm).

Set VLAN Members (MEMBERS)

To define which ports belong to a VLAN group, call naibrd_ESW_SetVLANMembers(). The members value is a bitmask where each bit corresponds to a port. Use the NAI_ESW_VLAN_MEMBER(i) macro to set individual port bits.

bQuit = GetVLANGroupNumber( cardIndex, module, maxGroup, DEF_ESW_VLAN_GROUP, &vlan );
if (!bQuit)
{
   vlanMembers = strtol( (const char *)inputBuffer, NULL, 16 );
   check_status( naibrd_ESW_SetVLANMembers( cardIndex, module, vlan, vlanMembers ) );
}

API parameters:

  • vlan — one-based VLAN group number.

  • members — hexadecimal bitmask of member ports. For example, 0x000F assigns ports 1-4 to the group.

Set VLAN Packet-Tagging Members (PACKET)

To define which member ports insert 802.1Q VLAN tags into packets as they ingress the switch, call naibrd_ESW_SetVLANMemberTagPkt(). The tagging bitmask uses the same port-to-bit mapping as the members bitmask.

bQuit = GetVLANGroupNumber( cardIndex, module, maxGroup, DEF_ESW_VLAN_GROUP, &vlan );
if (!bQuit)
{
   vlanTaggingMembers = strtol( (const char *)inputBuffer, NULL, 16 );
   check_status( naibrd_ESW_SetVLANMemberTagPkt( cardIndex, module, vlan, vlanTaggingMembers ) );
}

API parameters:

  • vlan — one-based VLAN group number.

  • tagPackets — hexadecimal bitmask of ports that should tag packets. Only ports that are also members of the VLAN group are affected.

Set VLAN IP Address (ADDRESS)

To assign an IP address to a VLAN group (required for subnet-based VLANs), call naibrd_ESW_SetVLANIPAddress(). The API accepts both IPv4 and IPv6 addresses. For IPv4, the address occupies the lower 32 bits (bits 31-0) and the upper 32 bits are set to zero. For IPv6, the API stores the upper 64 bits of the address; the lower 64 bits are not used.

parseFuncStatus = ParseIPv4orIPv6( (const char **)&ipText, AddrToWrite, &port, &IPv6Version );
if ( parseFuncStatus == 1 )
{
   if ( IPv6Version == TRUE )
   {
      ipBits63to48 = ( AddrToWrite[0] << 8 ) | ( AddrToWrite[1] );
      ipBits47to32 = ( AddrToWrite[2] << 8 ) | ( AddrToWrite[3] );
      ipBits31to16 = ( AddrToWrite[4] << 8 ) | ( AddrToWrite[5] );
      ipBits15to0 = ( AddrToWrite[6] << 8 ) | ( AddrToWrite[7] );
   }
   else
   {
      ipBits63to48 = 0;
      ipBits47to32 = 0;
      ipBits31to16 = ( AddrToWrite[0] << 8 ) | ( AddrToWrite[1] );
      ipBits15to0 = ( AddrToWrite[2] << 8 ) | ( AddrToWrite[3] );
   }
   check_status( naibrd_ESW_SetVLANIPAddress( cardIndex, module, vlan,
      ipBits63to48, ipBits47to32, ipBits31to16, ipBits15to0 ) );
}

API parameters:

  • vlan — one-based VLAN group number.

  • ip63to48, ip47to32, ip31to16, ip15to0 — four 16-bit segments of the IP address, from most significant to least significant.

Utility function: The sample uses ParseIPv4orIPv6() (from nai_ether_adv.h) to parse a user-entered IP string into a byte array and detect whether it is IPv4 or IPv6 format. In your own code, you can construct the four 16-bit values directly from your known IP address.

Set VLAN Network Mask (NET MASK)

To assign a network mask to a VLAN group (required for subnet-based VLANs), call naibrd_ESW_SetVLANNetworkMask(). The parameter layout is identical to naibrd_ESW_SetVLANIPAddress().

parseFuncStatus = ParseIPv4orIPv6( (const char **)&ipText, AddrToWrite, &port, &IPv6Version );
if ( parseFuncStatus == 1 )
{
   if ( IPv6Version == TRUE )
   {
      netBits63to48 = ( AddrToWrite[0] << 8 ) | ( AddrToWrite[1] );
      netBits47to32 = ( AddrToWrite[2] << 8 ) | ( AddrToWrite[3] );
      netBits31to16 = ( AddrToWrite[4] << 8 ) | ( AddrToWrite[5] );
      netBits15to0 = ( AddrToWrite[6] << 8 ) | ( AddrToWrite[7] );
   }
   else
   {
      netBits63to48 = 0;
      netBits47to32 = 0;
      netBits31to16 = ( AddrToWrite[0] << 8 ) | ( AddrToWrite[1] );
      netBits15to0 = ( AddrToWrite[2] << 8 ) | ( AddrToWrite[3] );
   }
   check_status( naibrd_ESW_SetVLANNetworkMask( cardIndex, module, vlan,
      netBits63to48, netBits47to32, netBits31to16, netBits15to0 ) );
}

API parameters:

  • vlan — one-based VLAN group number.

  • net63to48, net47to32, net31to16, net15to0 — four 16-bit segments of the network mask.

Important

Common Errors

  • NAI_ESW_VLAN_CFG_FAILED_ID_TAKEN (0x0004) — the VLAN ID you assigned is already in use by another group. Each group must have a unique VLAN ID. Clear the conflicting group or choose a different ID.

  • NAI_ESW_VLAN_CFG_FAILED_ID_ILLEGAL (0x0005) — the VLAN ID value is not valid. Consult your module’s manual for the range of legal VLAN IDs.

  • NAI_ESW_VLAN_CFG_MODIFYING_DISABLED_VLAN (0x0006) — you are modifying settings on a disabled VLAN group. This is informational; the settings will be stored but will not take effect until the group is enabled and confirmed.

  • NAI_ESW_VLAN_CFG_GENERAL_FAILURE (0x0007) — a general VLAN configuration failure occurred. Check that all required fields (ID, members, type) are set before confirming the group.

  • Configuration not taking effect — after setting VLAN parameters, you must set the confirm flag with naibrd_ESW_SetVLANControlConfirm() (or write NAI_ESW_VLAN_CTRL_CFG_INITIATE via the control word) for the switch to apply the new configuration. Check the return status to verify the result.

  • Invalid VLAN group number — VLAN group numbers are one-based. Use naibrd_ESW_GetVLANCount() to determine the maximum number of groups supported by your module.

Troubleshooting Reference

Note
This section summarizes errors covered in the preceding sections. Consult your module’s manual for hardware-specific diagnostics and register-level details.
Error / Symptom Possible Causes Suggested Resolution

No board found

Board is not powered on or not physically connected. Configuration file has incorrect interface or address.

Verify power and cabling. Re-run the board menu to reconfigure the connection.

Connection timeout

Network misconfiguration, firewall blocking traffic, IP mismatch (Ethernet). Bus misconfiguration (PCI/PCIe).

Check IP settings and firewall rules. Verify bus enumeration on PCI/PCIe systems.

Invalid card or module index

Card indices are zero-based; module indices are one-based. Value passed is out of range.

Confirm the correct indices for your hardware setup using the board menu.

Module not present at selected slot

The selected slot does not contain an H2 ESW module.

Use the board menu to verify slot population. Select the correct slot.

Link remains DOWN after speed/duplex change

Link partner is not connected, not powered, or configured for an incompatible speed/duplex.

Verify physical connectivity. Ensure both ends agree on speed and duplex settings or use auto-negotiation.

VLAN return status shows CFG_FAILED_ID_TAKEN (0x0004)

The VLAN ID is already assigned to another group.

Choose a unique VLAN ID or disable the conflicting group first.

VLAN return status shows CFG_FAILED_ID_ILLEGAL (0x0005)

The VLAN ID is outside the legal range.

Consult the module manual for valid VLAN ID values.

VLAN configuration not taking effect

The confirm flag was not set after configuring the group.

Call naibrd_ESW_SetVLANControlConfirm() with TRUE after setting all VLAN parameters, or write the control word with NAI_ESW_VLAN_CTRL_CFG_INITIATE set.

VLAN return status shows CFG_GENERAL_FAILURE (0x0007)

One or more required VLAN fields are missing or invalid.

Ensure VLAN ID, members, and type are all configured before confirming. Clear the return status and retry.

Invalid port or VLAN group number

Port numbers are one-based (1-12). VLAN group numbers are one-based. Value is out of range.

Use naibrd_ESW_GetPortCount() and naibrd_ESW_GetVLANCount() to determine valid ranges.

Full Source

Full Source — ESW_Config.c (SSK 1.x)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>

/* Common Sample Program include files */
#include "include/naiapp_boardaccess_menu.h"
#include "include/naiapp_boardaccess_query.h"
#include "include/naiapp_boardaccess_access.h"
#include "include/naiapp_boardaccess_display.h"
#include "include/naiapp_boardaccess_utils.h"

/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_esw.h"
#include "advanced/nai_ether_adv.h"

#define BACK_CHAR 'B'

static const int8_t *CONFIG_FILE = (const int8_t *)"default_ESW_Configuration.txt";

/* Function prototypes */
static bool_t Run_ESW_Config( int32_t cardIndex, int32_t module );

static nai_status_t Handle_ESW_PortConfig(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_ESW_VLANConfig(int32_t paramCount, int32_t* p_params);

static nai_status_t Handle_ESW_VLANID(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_ESW_VLANClearReturnStatus(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_ESW_VLANClearReturnStatusAllGroups(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_ESW_VLANEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_ESW_VLANType(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_ESW_VLANConfirm(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_ESW_VLANControlWord(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_ESW_VLANMembers(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_ESW_VLANTagging(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_ESW_VLANIPAddress(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_ESW_VLANNetworkMask(int32_t paramCount, int32_t* p_params);

static nai_status_t Handle_ESW_Duplex(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_ESW_Speed(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_ESW_Gigabit(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_ESW_DuplexWord(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_ESW_SpeedWord(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_ESW_GigabitWord(int32_t paramCount, int32_t* p_params);

void ESW_DisplayPortCfg( int32_t cardIndex, int32_t module, int32_t maxport );
void ESW_DisplayVLANCfg( int32_t cardIndex, int32_t module, int32_t maxgroup );
bool_t CheckESWModule( int32_t *pCardIndex, int32_t *pModule, uint32_t *pModid, int32_t GetPortCount( int32_t cardIndex, int32_t module ) );
bool_t GetPortNumber( int32_t cardIndex, int32_t module, int32_t MaxPort, int32_t DefPort, int32_t *Port );
bool_t GetVLANGroupNumber( int32_t cardIndex, int32_t module, int32_t MaxGroup, int32_t DefGroup, int32_t *Group );

static const int32_t DEF_ESW_PORT       = 1;
static const int32_t DEF_ESW_VLAN_GROUP = 1;

static int32_t g_MaxESWPorts = 0;
static uint32_t generation; /* generation of the board/module */

/****** Command Table *******/
enum esw_config_commands
{
   ESW_CONFIG_CMD_PORT_CONFIG,
   ESW_CONFIG_CMD_VLAN_CONFIG,
   ESW_CONFIG_CMD_COUNT
};

enum esw_port_config_commands
{
   ESW_PORT_CONFIG_CMD_DUPLEX,
   ESW_PORT_CONFIG_CMD_SPEED,
   ESW_PORT_CONFIG_CMD_GIGABIT,
   ESW_PORT_CONFIG_CMD_DUPLEX_WORD,
   ESW_PORT_CONFIG_CMD_SPEED_WORD,
   ESW_PORT_CONFIG_CMD_GIGABIT_WORD,
   ESW_PORT_CONFIG_CMD_COUNT
};

enum esw_vlan_config_commands
{
   ESW_VLAN_CONFIG_CMD_ID,
   ESW_VLAN_CONFIG_CMD_CLEAR_STATUS,
   ESW_VLAN_CONFIG_CMD_CLEAR_STATUS_ALL_GROUPS,
   ESW_VLAN_CONFIG_CMD_ENABLE,
   ESW_VLAN_CONFIG_CMD_TYPE,
   ESW_VLAN_CONFIG_CMD_CONFIRM,
   ESW_VLAN_CONFIG_CMD_CTRL_WORD,
   ESW_VLAN_CONFIG_CMD_MEMBERS,
   ESW_VLAN_CONFIG_CMD_TAGGING,
   ESW_VLAN_CONFIG_CMD_IP_ADDRESS,
   ESW_VLAN_CONFIG_CMD_NET_MASK,
   ESW_VLAN_CONFIG_CMD_COUNT
};

/****** Command Tables *******/
naiapp_cmdtbl_params_t ESW_ConfigMenuCmds[] =
{
   {"PORT",      "ESW Port Configuration Functions",      ESW_CONFIG_CMD_PORT_CONFIG,       Handle_ESW_PortConfig},
   {"VLAN",      "ESW VLAN Configuration Functions",      ESW_CONFIG_CMD_VLAN_CONFIG,       Handle_ESW_VLANConfig}
};

naiapp_cmdtbl_params_t ESW_PortConfigMenuCmds[] =
{
   {"DUPLEX",      "Set Link Duplex Mode of Port",                             ESW_PORT_CONFIG_CMD_DUPLEX,                  Handle_ESW_Duplex},
   {"SPEED",       "Set Link Speed of Port",                                   ESW_PORT_CONFIG_CMD_SPEED,                   Handle_ESW_Speed},
   {"GIGABIT",     "Set Link Gigabit Capability Advertise State of Port",      ESW_PORT_CONFIG_CMD_GIGABIT,                 Handle_ESW_Gigabit},
   {"RDUPLEX",     "Set Raw Link Duplex Mode Register",                        ESW_PORT_CONFIG_CMD_DUPLEX_WORD,             Handle_ESW_DuplexWord},
   {"RSPEED",      "Set Raw Link Speed Group Registers",                       ESW_PORT_CONFIG_CMD_SPEED_WORD,              Handle_ESW_SpeedWord},
   {"RGIGABIT",    "Set Raw Link Gigabit Capability Advertise Register Value", ESW_PORT_CONFIG_CMD_GIGABIT_WORD,            Handle_ESW_GigabitWord}
};

naiapp_cmdtbl_params_t ESW_VLANConfigMenuCmds[] =
{
   {"ID",           "Set VLAN ID",                                 ESW_VLAN_CONFIG_CMD_ID,                      Handle_ESW_VLANID},
   {"CLEAR",        "Clear VLAN Return Status",                    ESW_VLAN_CONFIG_CMD_CLEAR_STATUS,            Handle_ESW_VLANClearReturnStatus},
   {"GROUP CLEAR",  "Clear VLAN Return Status All Groups",         ESW_VLAN_CONFIG_CMD_CLEAR_STATUS_ALL_GROUPS, Handle_ESW_VLANClearReturnStatusAllGroups},
   {"ENABLE",       "Enable/disable VLAN",                         ESW_VLAN_CONFIG_CMD_ENABLE,                  Handle_ESW_VLANEnable},
   {"TYPE",         "Set VLAN Type",                               ESW_VLAN_CONFIG_CMD_TYPE,                    Handle_ESW_VLANType},
   {"VLAN CONFIRM", "Set VLAN Confirm Flag Value",                 ESW_VLAN_CONFIG_CMD_CONFIRM,                 Handle_ESW_VLANConfirm},
   {"RAW CTRL",     "Set VLAN Control Reg Value",                  ESW_VLAN_CONFIG_CMD_CTRL_WORD,               Handle_ESW_VLANControlWord},
   {"MEMBERS",      "Set VLAN Members",                            ESW_VLAN_CONFIG_CMD_MEMBERS,                 Handle_ESW_VLANMembers},
   {"PACKET",       "Set VLAN Packet-Tagging Members",             ESW_VLAN_CONFIG_CMD_TAGGING,                 Handle_ESW_VLANTagging},
   {"ADDRESS",      "Set VLAN IP Address",                         ESW_VLAN_CONFIG_CMD_IP_ADDRESS,              Handle_ESW_VLANIPAddress},
   {"NET MASK",     "Set VLAN Network Mask",                       ESW_VLAN_CONFIG_CMD_NET_MASK,                Handle_ESW_VLANNetworkMask}
};

/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t ESW_Config(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = FALSE;
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
   {
      while (stop != TRUE)
      {
         /* Query the user for the card index */
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         if (stop != TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));

            /* Query the user for the module number */
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != TRUE)
            {
               Run_ESW_Config(cardIndex, module);

            }
         }

         printf("\nType Q to quit or Enter key to restart application:\n");
         stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      }
   }

   printf("\nType the Enter key to exit the program: ");
   naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   naiapp_access_CloseAllOpenCards();

   return 0;
}

/**************************************************************************************************************/
static bool_t Run_ESW_Config( int32_t cardIndex, int32_t module )
{
   bool_t bQuit = FALSE;
   bool_t bContinue = TRUE;
   bool_t bCmdFound = FALSE;
   int32_t cmd;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   naiapp_AppParameters_t  esw_params;
   p_naiapp_AppParameters_t esw_config_params = &esw_params;
   esw_config_params->cardIndex = cardIndex;
   esw_config_params->module = module;

   /* Get the Maximum number of ESW Ports */
   g_MaxESWPorts = naibrd_ESW_GetPortCount( cardIndex, module );
   esw_config_params->channel = g_MaxESWPorts;
   /* Get the generation of the board and module */
   naibrd_GetBoardGen( cardIndex, &generation );

   while (bContinue)
   {
      naiapp_utils_LoadParamMenuCommands( ESW_CONFIG_CMD_COUNT, ESW_ConfigMenuCmds );
      while (bContinue)
      {
         naiapp_utils_LoadParamMenuCommands( ESW_CONFIG_CMD_COUNT, ESW_ConfigMenuCmds ); /* reload main menu */
         naiapp_display_ParamMenuCommands( (int8_t *)"ESW Configuration Menu" );
         printf( "\nType ESW command or %c to quit : main >", NAI_QUIT_CHAR );
         bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
         if (!bQuit)
         {
            if ( inputResponseCnt > 0 )
            {
               bCmdFound = naiapp_utils_GetParamMenuCmdNum( inputResponseCnt, inputBuffer, &cmd );
               if (bCmdFound)
               {
                  switch (cmd)
                  {
                  case ESW_CONFIG_CMD_PORT_CONFIG:
                  case ESW_CONFIG_CMD_VLAN_CONFIG:
                     ESW_ConfigMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)esw_config_params);
                     break;
                  default:
                     printf( "Invalid command entered\n" );
                     break;
                  }
               }
               else
                  printf( "Invalid command entered\n" );
            }
         }
         else
            bContinue = FALSE;
      }
   }
   return bQuit;
}

/**************************************************************************************************************/
static nai_status_t Handle_ESW_PortConfig(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_esw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_esw_params->cardIndex;
   int32_t module = p_esw_params->module;
   bool_t bQuit = FALSE;
   bool_t bContinue = TRUE;
   bool_t bCmdFound = FALSE;
   int32_t cmd;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   while (bContinue)
   {
      naiapp_utils_LoadParamMenuCommands( ESW_PORT_CONFIG_CMD_COUNT, ESW_PortConfigMenuCmds );
      while (bContinue)
      {
         ESW_DisplayPortCfg( cardIndex, module, g_MaxESWPorts );
         naiapp_display_ParamMenuCommands( (int8_t *)"ESW Port Configuration Menu" );
         printf( "\nType ESW command or %c to go back : Port Cfg >", BACK_CHAR );
         bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), BACK_CHAR, inputBuffer, &inputResponseCnt );
         if (!bQuit)
         {
            if ( inputResponseCnt > 0 )
            {
               bCmdFound = naiapp_utils_GetParamMenuCmdNum( inputResponseCnt, inputBuffer, &cmd );
               if (bCmdFound)
               {
                  switch (cmd)
                  {
                  case ESW_PORT_CONFIG_CMD_DUPLEX:
                  case ESW_PORT_CONFIG_CMD_SPEED:
                  case ESW_PORT_CONFIG_CMD_GIGABIT:
                  case ESW_PORT_CONFIG_CMD_DUPLEX_WORD:
                  case ESW_PORT_CONFIG_CMD_SPEED_WORD:
                  case ESW_PORT_CONFIG_CMD_GIGABIT_WORD:
                     ESW_PortConfigMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)p_esw_params);
                     break;
                  default:
                     printf( "Invalid command entered\n" );
                     break;
                  }
               }
               else
                  printf( "Invalid command entered\n" );
            }
         }
         else
            bContinue = FALSE;
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
static nai_status_t Handle_ESW_VLANConfig(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t bContinue = TRUE;
   bool_t bCmdFound = FALSE;
   int32_t cmd;
   p_naiapp_AppParameters_t p_esw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_esw_params->cardIndex;
   int32_t module = p_esw_params->module;
   int32_t maxGroup = naibrd_ESW_GetVLANCount( cardIndex, module );
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   while (bContinue)
   {
      naiapp_utils_LoadParamMenuCommands( ESW_VLAN_CONFIG_CMD_COUNT, ESW_VLANConfigMenuCmds );
      while (bContinue)
      {
         ESW_DisplayVLANCfg( cardIndex, module, maxGroup );
         naiapp_display_ParamMenuCommands( (int8_t *)"ESW VLAN Configuration Menu" );
         printf( "\nType ESW command or %c to go back : VLAN Cfg >", BACK_CHAR );
         bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), BACK_CHAR, inputBuffer, &inputResponseCnt );
         if (!bQuit)
         {
            if ( inputResponseCnt > 0 )
            {
               bCmdFound = naiapp_utils_GetParamMenuCmdNum( inputResponseCnt, inputBuffer, &cmd );
               if (bCmdFound)
               {
                  switch (cmd)
                  {
                  case ESW_VLAN_CONFIG_CMD_ID:
                  case ESW_VLAN_CONFIG_CMD_CLEAR_STATUS:
                  case ESW_VLAN_CONFIG_CMD_CLEAR_STATUS_ALL_GROUPS:
                  case ESW_VLAN_CONFIG_CMD_ENABLE:
                  case ESW_VLAN_CONFIG_CMD_TYPE:
                  case ESW_VLAN_CONFIG_CMD_CONFIRM:
                  case ESW_VLAN_CONFIG_CMD_CTRL_WORD:
                  case ESW_VLAN_CONFIG_CMD_MEMBERS:
                  case ESW_VLAN_CONFIG_CMD_TAGGING:
                  case ESW_VLAN_CONFIG_CMD_IP_ADDRESS:
                  case ESW_VLAN_CONFIG_CMD_NET_MASK:
                     ESW_VLANConfigMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)p_esw_params);
                     break;
                  default:
                     printf( "Invalid command entered\n" );
                     break;
                  }
               }
               else
                  printf( "Invalid command entered\n" );
            }
         }
         else
            bContinue = FALSE;
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
static nai_status_t Handle_ESW_VLANID(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t vlanid;
   p_naiapp_AppParameters_t p_esw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_esw_params->cardIndex;
   int32_t module = p_esw_params->module;
   int32_t vlan = p_esw_params->channel;
   int32_t maxGroup = naibrd_ESW_GetVLANCount( cardIndex, module );
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   bQuit = GetVLANGroupNumber( cardIndex, module, maxGroup, DEF_ESW_VLAN_GROUP, &vlan );
   if (!bQuit)
   {
      printf( "Type VLAN Group ID hexadecimal value to set (example:ffff): " );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if ( inputResponseCnt > 0 )
         {
            vlanid = strtol( (const char *)inputBuffer, NULL, 16 );
            check_status( naibrd_ESW_SetVLANID( cardIndex, module, vlan, vlanid ) );
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
static nai_status_t Handle_ESW_VLANClearReturnStatus(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   p_naiapp_AppParameters_t p_esw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_esw_params->cardIndex;
   int32_t module = p_esw_params->module;
   int32_t vlan = p_esw_params->channel;
   int32_t maxGroup = naibrd_ESW_GetVLANCount( cardIndex, module );
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   bQuit = GetVLANGroupNumber( cardIndex, module, maxGroup, DEF_ESW_VLAN_GROUP, &vlan );
   if (!bQuit)
   {
      printf( "Are you sure you want to clear the return status of VLAN Group %d? ('Y' for Yes or 'N' for No)(default:Y): ", vlan );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if ( ( inputBuffer[0] == 'Y' ) || ( inputBuffer[0] == 'y' ) || ( inputResponseCnt == 0 ) )
         {
            check_status( naibrd_ESW_ClearVLANReturnStatus( cardIndex, module, vlan ) );
            printf( "\nReturn Status for VLAN Group %d has been cleared.\n", vlan );
         }
         else if ( ( inputBuffer[0] == 'N' ) || ( inputBuffer[0] == 'n' ) )
         {
            printf( "\nNo Return Statuses have been cleared.\n" );
         }
         else
         {
            printf( "\nERROR! The response you entered was invalid.\n" );
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
static nai_status_t Handle_ESW_VLANClearReturnStatusAllGroups(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_esw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_esw_params->cardIndex;
   int32_t module = p_esw_params->module;
   int32_t vlan = p_esw_params->channel;
   bool_t bQuit = FALSE;
   int32_t numVLANGroups = naibrd_ESW_GetVLANCount( cardIndex, module );
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   printf( "Are you sure you want to clear the return statuses of all of the VLAN Groups on the module? ('Y' for Yes or 'N' for No)(default:Y): " );
   bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
   if (!bQuit)
   {
      if ( ( inputBuffer[0] == 'Y' ) || ( inputBuffer[0] == 'y' ) || ( inputResponseCnt == 0 ) )
      {
         for ( vlan = 1; vlan <= numVLANGroups; vlan++ )
         {
            check_status( naibrd_ESW_ClearVLANReturnStatus( cardIndex, module, vlan ) );
         }
         printf( "\nReturn Statuses for all VLAN Groups have been cleared.\n" );
      }
      else if ( ( inputBuffer[0] == 'N' ) || ( inputBuffer[0] == 'n' ) )
      {
         printf( "\nNo Return Statuses have been cleared.\n" );
      }
      else
      {
         printf( "\nERROR! The response you entered was invalid.\n" );
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
static nai_status_t Handle_ESW_VLANEnable(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t errFlag = FALSE;
   bool_t vlanEnable;
   p_naiapp_AppParameters_t p_esw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_esw_params->cardIndex;
   int32_t module = p_esw_params->module;
   int32_t vlan = p_esw_params->channel;
   int32_t maxGroup = naibrd_ESW_GetVLANCount( cardIndex, module );
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   bQuit = GetVLANGroupNumber( cardIndex, module, maxGroup, DEF_ESW_VLAN_GROUP, &vlan );
   if (!bQuit)
   {
      printf( "Type VLAN Enabled/Disabled State value to set ('0' for Disable, '1' for Enable)(default:1): " );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if ( inputResponseCnt == 0 )
         {
            vlanEnable = TRUE;
         }
         else if ( inputResponseCnt > 0 )
         {
            vlanEnable = (bool_t)( atoi( (const char *)inputBuffer ) );
         }
         else
         {
            vlanEnable = FALSE;
            errFlag = TRUE;
         }

         if ( ( ( vlanEnable == TRUE ) || ( vlanEnable == FALSE ) ) && ( errFlag == FALSE ) )
         {
            check_status( naibrd_ESW_SetVLANControlEnable( cardIndex, module, vlan, vlanEnable ) );
         }
         else
         {
            printf( "\nERROR! Invalid VLAN Enable value.\n" );
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
static nai_status_t Handle_ESW_VLANType(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t errFlag = FALSE;
   nai_esw_vlan_type_t vlanType;
   p_naiapp_AppParameters_t p_esw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_esw_params->cardIndex;
   int32_t module = p_esw_params->module;
   int32_t vlan = p_esw_params->channel;
   int32_t maxGroup = naibrd_ESW_GetVLANCount( cardIndex, module );
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   bQuit = GetVLANGroupNumber( cardIndex, module, maxGroup, DEF_ESW_VLAN_GROUP, &vlan );
   if (!bQuit)
   {
      printf( "Type VLAN Type value to set ('0' for port based, '1' for subnet based)(default:0): " );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if ( inputResponseCnt == 0 )
         {
            vlanType = NAI_ESW_VLAN_TYPE_PORT_BASED;
         }
         else if ( inputResponseCnt > 0 )
         {
            vlanType = (nai_esw_vlan_type_t)( atoi( (const char *)inputBuffer ) );
         }
         else
         {
            vlanType = NAI_ESW_VLAN_TYPE_PORT_BASED;
            errFlag = TRUE;
         }

         if ( ( ( vlanType == NAI_ESW_VLAN_TYPE_SUBNET_BASED ) || ( vlanType == NAI_ESW_VLAN_TYPE_PORT_BASED ) ) && ( errFlag == FALSE ) )
         {
            check_status( naibrd_ESW_SetVLANControlType( cardIndex, module, vlan, vlanType ) );
         }
         else
         {
            printf( "\nERROR! Invalid VLAN Control Type.\n" );
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
static nai_status_t Handle_ESW_VLANConfirm(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t errFlag = FALSE;
   bool_t confirm;
   p_naiapp_AppParameters_t p_esw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_esw_params->cardIndex;
   int32_t module = p_esw_params->module;
   int32_t vlan = p_esw_params->channel;
   int32_t maxGroup = naibrd_ESW_GetVLANCount( cardIndex, module );
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   bQuit = GetVLANGroupNumber( cardIndex, module, maxGroup, DEF_ESW_VLAN_GROUP, &vlan );
   if (!bQuit)
   {
      printf( "Type VLAN Confirm Flag value to set ('1' for confirm, '0' for not confirm)(default:1): " );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if ( inputResponseCnt == 0 )
         {
            confirm = TRUE;
         }
         else if ( inputResponseCnt > 0 )
         {
            confirm = (bool_t)( atoi( (const char *)inputBuffer ) );
         }
         else
         {
            confirm = FALSE;
            errFlag = TRUE;
         }

         if ( ( ( confirm == TRUE ) || ( confirm == FALSE ) ) && ( errFlag == FALSE ) )
         {
            check_status( naibrd_ESW_SetVLANControlConfirm( cardIndex, module, vlan, confirm ) );
         }
         else
         {
            printf( "\nERROR! Invalid VLAN Confirm Flag Value.\n" );
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
static nai_status_t Handle_ESW_VLANControlWord(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   nai_esw_vlan_ctrl_t control;
   p_naiapp_AppParameters_t p_esw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_esw_params->cardIndex;
   int32_t module = p_esw_params->module;
   int32_t vlan = p_esw_params->channel;
   int32_t maxGroup = naibrd_ESW_GetVLANCount( cardIndex, module );
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   bQuit = GetVLANGroupNumber( cardIndex, module, maxGroup, DEF_ESW_VLAN_GROUP, &vlan );
   if (!bQuit)
   {
      printf( "Type Raw VLAN Control hexadecimal value to set (example:ffff): " );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if ( inputResponseCnt > 0 )
         {
            control = strtol( (const char *)inputBuffer, NULL, 16 );
            check_status( naibrd_ESW_SetVLANControlWord( cardIndex, module, vlan, control ) );
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
static nai_status_t Handle_ESW_VLANMembers(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t vlanMembers;
   p_naiapp_AppParameters_t p_esw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_esw_params->cardIndex;
   int32_t module = p_esw_params->module;
   int32_t vlan = p_esw_params->channel;
   int32_t maxGroup = naibrd_ESW_GetVLANCount( cardIndex, module );
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   bQuit = GetVLANGroupNumber( cardIndex, module, maxGroup, DEF_ESW_VLAN_GROUP, &vlan );
   if (!bQuit)
   {
      printf( "Type VLAN Members hexadecimal value to set (example:ffff): " );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if ( inputResponseCnt > 0 )
         {
            vlanMembers = strtol( (const char *)inputBuffer, NULL, 16 );
            check_status( naibrd_ESW_SetVLANMembers( cardIndex, module, vlan, vlanMembers ) );
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
static nai_status_t Handle_ESW_VLANTagging(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t vlanTaggingMembers;
   p_naiapp_AppParameters_t p_esw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_esw_params->cardIndex;
   int32_t module = p_esw_params->module;
   int32_t vlan = p_esw_params->channel;
   int32_t maxGroup = naibrd_ESW_GetVLANCount( cardIndex, module );
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   bQuit = GetVLANGroupNumber( cardIndex, module, maxGroup, DEF_ESW_VLAN_GROUP, &vlan );
   if (!bQuit)
   {
      printf( "Type VLAN Packet-Tagging Members hexadecimal value to set (example:ffff): " );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if ( inputResponseCnt > 0 )
         {
            vlanTaggingMembers = strtol( (const char *)inputBuffer, NULL, 16 );
            check_status( naibrd_ESW_SetVLANMemberTagPkt( cardIndex, module, vlan, vlanTaggingMembers ) );
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
static nai_status_t Handle_ESW_VLANIPAddress(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint8_t AddrToWrite[10];
   int32_t IPv6Version = 0;
   int32_t parseFuncStatus;
   uint16_t ipBits63to48;
   uint16_t ipBits47to32;
   uint16_t ipBits31to16;
   uint16_t ipBits15to0;
   int32_t port = 0;
   int8_t* ipText;
   p_naiapp_AppParameters_t p_esw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_esw_params->cardIndex;
   int32_t module = p_esw_params->module;
   int32_t vlan = p_esw_params->channel;
   int32_t maxGroup = naibrd_ESW_GetVLANCount( cardIndex, module );
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   bQuit = GetVLANGroupNumber( cardIndex, module, maxGroup, DEF_ESW_VLAN_GROUP, &vlan );
   if (!bQuit)
   {
      printf( "Type VLAN IP Address to set in either IPv4 or IPv6 format (for IPv6, only type in the upper 64 bits of the address, " );
      printf( "as the lower 64 bits are not used)(IPv4 example: 255.255.255.255, IPv6 example: FFFF:FFFF:FFFF:FFFF): " );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         ipText = &inputBuffer[0];
         parseFuncStatus = ParseIPv4orIPv6( (const char **)&ipText, AddrToWrite, &port, &IPv6Version );
         if ( parseFuncStatus == 1 )
         {
            if ( IPv6Version == TRUE )
            {
               ipBits63to48 = ( AddrToWrite[0] << 8 ) | ( AddrToWrite[1] );
               ipBits47to32 = ( AddrToWrite[2] << 8 ) | ( AddrToWrite[3] );
               ipBits31to16 = ( AddrToWrite[4] << 8 ) | ( AddrToWrite[5] );
               ipBits15to0 = ( AddrToWrite[6] << 8 ) | ( AddrToWrite[7] );
            }
            else
            {
               ipBits63to48 = 0;
               ipBits47to32 = 0;
               ipBits31to16 = ( AddrToWrite[0] << 8 ) | ( AddrToWrite[1] );
               ipBits15to0 = ( AddrToWrite[2] << 8 ) | ( AddrToWrite[3] );
            }
            check_status( naibrd_ESW_SetVLANIPAddress( cardIndex, module, vlan, ipBits63to48, ipBits47to32, ipBits31to16, ipBits15to0 ) );
         }
         else
         {
            printf( "\nERROR! Invalid IP Address.\n" );
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
static nai_status_t Handle_ESW_VLANNetworkMask(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint8_t AddrToWrite[10];
   int32_t IPv6Version = 0;
   int32_t parseFuncStatus;
   uint16_t netBits63to48;
   uint16_t netBits47to32;
   uint16_t netBits31to16;
   uint16_t netBits15to0;
   int32_t port = 0;
   int8_t* ipText;
   p_naiapp_AppParameters_t p_esw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_esw_params->cardIndex;
   int32_t module = p_esw_params->module;
   int32_t vlan = p_esw_params->channel;
   int32_t maxGroup = naibrd_ESW_GetVLANCount( cardIndex, module );
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   bQuit = GetVLANGroupNumber( cardIndex, module, maxGroup, DEF_ESW_VLAN_GROUP, &vlan );
   if (!bQuit)
   {
      printf( "Type VLAN Network Mask to set in either IPv4 or IPv6 format (for IPv6, only type in the upper 64 bits of the mask, " );
      printf( "as the lower 64 bits are not used)(IPv4 example: 255.255.255.255, IPv6 example: FFFF:FFFF:FFFF:FFFF): " );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         ipText = &inputBuffer[0];
         parseFuncStatus = ParseIPv4orIPv6( (const char **)&ipText, AddrToWrite, &port, &IPv6Version );
         if ( parseFuncStatus == 1 )
         {
            if ( IPv6Version == TRUE )
            {
               netBits63to48 = ( AddrToWrite[0] << 8 ) | ( AddrToWrite[1] );
               netBits47to32 = ( AddrToWrite[2] << 8 ) | ( AddrToWrite[3] );
               netBits31to16 = ( AddrToWrite[4] << 8 ) | ( AddrToWrite[5] );
               netBits15to0 = ( AddrToWrite[6] << 8 ) | ( AddrToWrite[7] );
            }
            else
            {
               netBits63to48 = 0;
               netBits47to32 = 0;
               netBits31to16 = ( AddrToWrite[0] << 8 ) | ( AddrToWrite[1] );
               netBits15to0 = ( AddrToWrite[2] << 8 ) | ( AddrToWrite[3] );
            }
            check_status( naibrd_ESW_SetVLANNetworkMask( cardIndex, module, vlan, netBits63to48, netBits47to32, netBits31to16, netBits15to0 ) );
         }
         else
         {
            printf( "\nERROR! Invalid Network Mask.\n" );
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
static nai_status_t Handle_ESW_Duplex(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t errFlag = FALSE;
   nai_esw_link_duplex_t duplex;
   p_naiapp_AppParameters_t p_esw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_esw_params->cardIndex;
   int32_t module = p_esw_params->module;
   int32_t port = p_esw_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   bQuit = GetPortNumber( cardIndex, module, g_MaxESWPorts, DEF_ESW_PORT, &port );
   if (!bQuit)
   {
      printf( "Type Link Duplex value to set ('0' for Half Duplex, '1' for Full Duplex)(default:0): " );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if ( inputResponseCnt == 0 )
         {
            duplex = NAI_ESW_LINK_HALF_DUPLEX;
         }
         else if ( inputResponseCnt > 0 )
         {
            duplex = (nai_esw_link_duplex_t)( atoi( (const char *)inputBuffer ) );
         }
         else
         {
            duplex = NAI_ESW_LINK_HALF_DUPLEX;
            errFlag = TRUE;
         }

         if ( ( ( duplex == NAI_ESW_LINK_HALF_DUPLEX ) || ( duplex == NAI_ESW_LINK_FULL_DUPLEX ) ) && ( errFlag == FALSE ) )
         {
            check_status( naibrd_ESW_SetLinkDuplex( cardIndex, module, port, duplex ) );
         }
         else
         {
            printf( "\nERROR! Invalid Link Duplex value.\n" );
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
static nai_status_t Handle_ESW_Speed(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t errFlag = FALSE;
   nai_esw_link_speed_t speed;
   p_naiapp_AppParameters_t p_esw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_esw_params->cardIndex;
   int32_t module = p_esw_params->module;
   int32_t port = p_esw_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   bQuit = GetPortNumber( cardIndex, module, g_MaxESWPorts, DEF_ESW_PORT, &port );
   if (!bQuit)
   {
      printf( "Type Link Speed value to set ('0' for Auto, '1' for 10, '2' for 100, '3' for 1G, '15' for disable)(default:0): " );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if ( inputResponseCnt == 0 )
         {
            speed = NAI_ESW_LINK_SPEED_AUTO;
         }
         else if ( inputResponseCnt > 0 )
         {
            speed = (nai_esw_link_speed_t)( atoi( (const char *)inputBuffer ) );
         }
         else
         {
            speed = NAI_ESW_LINK_SPEED_DISABLE;
            errFlag = TRUE;
         }

         if ( ( ( speed == NAI_ESW_LINK_SPEED_AUTO ) || ( speed == NAI_ESW_LINK_SPEED_10 ) || ( speed == NAI_ESW_LINK_SPEED_100 ) || ( speed == NAI_ESW_LINK_SPEED_1G ) || ( speed == NAI_ESW_LINK_SPEED_DISABLE ) ) && ( errFlag == FALSE ) )
         {
            check_status( naibrd_ESW_SetLinkSpeed( cardIndex, module, port, speed ) );
         }
         else
         {
            printf( "\nERROR! Invalid Link Speed value.\n" );
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
static nai_status_t Handle_ESW_Gigabit(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t errFlag = FALSE;
   nai_esw_link_gig_adv_t linkGigAdv;
   p_naiapp_AppParameters_t p_esw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_esw_params->cardIndex;
   int32_t module = p_esw_params->module;
   int32_t port = p_esw_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   bQuit = GetPortNumber( cardIndex, module, g_MaxESWPorts, DEF_ESW_PORT, &port );
   if (!bQuit)
   {
      printf( "Type Link Gigabit Capability Advertise state to set ('0' for Off, '1' for On)(default:0): " );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if ( inputResponseCnt == 0 )
         {
            linkGigAdv = NAI_ESW_LINK_GIG_ADV_OFF;
         }
         else if ( inputResponseCnt > 0 )
         {
            linkGigAdv = (nai_esw_link_gig_adv_t)( atoi( (const char *)inputBuffer ) );
         }
         else
         {
            linkGigAdv = NAI_ESW_LINK_GIG_ADV_OFF;
            errFlag = TRUE;
         }

         if ( ( ( linkGigAdv == NAI_ESW_LINK_GIG_ADV_OFF ) || ( linkGigAdv == NAI_ESW_LINK_GIG_ADV_ON ) ) && ( errFlag == FALSE ) )
         {
            check_status( naibrd_ESW_SetLinkGigCapAdv( cardIndex, module, port, linkGigAdv ) );
         }
         else
         {
            printf( "\nERROR! Invalid Link Gigabit Capability Advertise State.\n" );
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
static nai_status_t Handle_ESW_DuplexWord(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t duplexWord;
   p_naiapp_AppParameters_t p_esw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_esw_params->cardIndex;
   int32_t module = p_esw_params->module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   printf( "Type Raw Link Duplex value to set (example:ffff): " );
   bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
   if (!bQuit)
   {
      if ( inputResponseCnt > 0 )
      {
         duplexWord = strtol( (const char *)inputBuffer, NULL, 16 );
         check_status( naibrd_ESW_SetLinkDuplexWord( cardIndex, module, duplexWord ) );
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
static nai_status_t Handle_ESW_SpeedWord(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t speedWord;
   int32_t group;
   p_naiapp_AppParameters_t p_esw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_esw_params->cardIndex;
   int32_t module = p_esw_params->module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   printf( "Would you like to set the Raw Link Speed value for ports 1-4, 5-8, or 9-12? ('1' for 1-4, '2' for 5-8, '3' for 9-12)(default:1): " );
   bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
   if (!bQuit)
   {
      if ( inputResponseCnt > 0 )
      {
         group = atoi( (const char *)inputBuffer );
         if ( ( group > 3 ) || ( group < 1 ) )
         {
            printf( "\nERROR! Invalid group number.\n" );
            bQuit = TRUE;
         }
      }
      else if ( inputResponseCnt == 0 )
      {
         group = 1;
      }
      else
      {
         group = 0xFFFF;
         printf( "\nERROR!\n" );
         bQuit = TRUE;
      }

      if (!bQuit)
      {
         printf( "Type Raw Link Speed value to set (example:ffff): " );
         bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
         if (!bQuit)
         {
            if ( inputResponseCnt > 0 )
            {
               speedWord = strtol( (const char *)inputBuffer, NULL, 16 );
               check_status( naibrd_ESW_SetLinkSpeedWord( cardIndex, module, group, speedWord ) );
            }
         }
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
static nai_status_t Handle_ESW_GigabitWord(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t gigabitWord;
   p_naiapp_AppParameters_t p_esw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_esw_params->cardIndex;
   int32_t module = p_esw_params->module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   printf( "Type Raw Link Gigabit Capability Advertise state to set (example:ffff): " );
   bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
   if (!bQuit)
   {
      if ( inputResponseCnt > 0 )
      {
         gigabitWord = strtol( (const char *)inputBuffer, NULL, 16 );
         check_status( naibrd_ESW_SetLinkGigCapAdvWord( cardIndex, module, gigabitWord ) );
      }
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
void ESW_DisplayPortCfg( int32_t cardIndex, int32_t module, int32_t maxport )
{
   int32_t port;
   nai_esw_link_status_t status;
   nai_esw_link_duplex_t duplex;
   nai_esw_link_duplex_t duplexStatus;
   nai_esw_link_speed_t speed;
   nai_esw_link_speed_t speedStatus;
   nai_esw_link_gig_adv_t gigabit;
   nai_esw_link_mdix_mode_t mdix;
   nai_esw_bit_status_t bitStatus;
   uint32_t statusWord;
   uint32_t duplexWord;
   uint32_t duplexStatusWord;
   uint32_t speedWord14;
   uint32_t speedWord58;
   uint32_t speedWord912;
   uint32_t speedStatusWord14;
   uint32_t speedStatusWord58;
   uint32_t speedStatusWord912;
   uint32_t gigabitWord;
   uint32_t mdixWord;
   uint32_t bitStatusWord;
   char* sStatus;
   char* sDuplex;
   char* sDuplexStatus;
   char* sSpeed;
   char* sSpeedStatus;
   char* sGigabit;
   char* sMdix;
   char* sBitStatus;

   printf( "\n\nESW Port Configuration:\n" );
   printf( "                         Duplex                         Speed                        BIT\n" );
   printf( "Port   Status   Duplex   Status                Speed    Status    Gigabit   MDI/X   Status\n" );
   printf( "----------------------------------------------------------------------------------------------\n" );

   check_status( naibrd_ESW_GetLinkStatusWord( cardIndex, module, &statusWord ) );
   check_status( naibrd_ESW_GetLinkDuplexWord( cardIndex, module, &duplexWord ) );
   check_status( naibrd_ESW_GetLinkDuplexStatusWord( cardIndex, module, &duplexStatusWord ) );
   check_status( naibrd_ESW_GetLinkSpeedWord( cardIndex, module, 1, &speedWord14 ) );
   check_status( naibrd_ESW_GetLinkSpeedWord( cardIndex, module, 2, &speedWord58 ) );
   check_status( naibrd_ESW_GetLinkSpeedWord( cardIndex, module, 3, &speedWord912 ) );
   check_status( naibrd_ESW_GetGroupLinkSpeedStatus( cardIndex, module, 1, &speedStatusWord14 ) );
   check_status( naibrd_ESW_GetGroupLinkSpeedStatus( cardIndex, module, 2, &speedStatusWord58 ) );
   check_status( naibrd_ESW_GetGroupLinkSpeedStatus( cardIndex, module, 3, &speedStatusWord912 ) );
   check_status( naibrd_ESW_GetLinkGigCapAdvWord( cardIndex, module, &gigabitWord ) );
   check_status( naibrd_ESW_GetLinkMDIXModeWord( cardIndex, module, &mdixWord ) );
   check_status( naibrd_ESW_GetBITStatusWord( cardIndex, module, &bitStatusWord ) );

   for ( port = 1; port <= maxport; port++ )
   {
      check_status( naibrd_ESW_GetLinkStatus( cardIndex, module, port, &status ) );
      switch (status)
      {
      case NAI_ESW_LINK_DOWN:
         sStatus = " DOWN ";
         break;
      case NAI_ESW_LINK_UP:
         sStatus = "  UP  ";
         break;
      default:
         sStatus = " ERROR";
         break;
      }

      check_status( naibrd_ESW_GetLinkDuplex( cardIndex, module, port, &duplex ) );
      switch (duplex)
      {
      case NAI_ESW_LINK_HALF_DUPLEX:
         sDuplex = " HALF ";
         break;
      case NAI_ESW_LINK_FULL_DUPLEX:
         sDuplex = " FULL ";
         break;
      default:
         sDuplex = " ERROR";
         break;
      }

      check_status( naibrd_ESW_GetLinkDuplexStatus( cardIndex, module, port, &duplexStatus ) );
      switch (duplexStatus)
      {
      case NAI_ESW_LINK_HALF_DUPLEX:
         sDuplexStatus = " HALF ";
         break;
      case NAI_ESW_LINK_FULL_DUPLEX:
         sDuplexStatus = " FULL ";
         break;
      default:
         sDuplexStatus = " ERROR";
         break;
      }

      check_status( naibrd_ESW_GetLinkSpeed( cardIndex, module, port, &speed ) );
      switch (speed)
      {
      case NAI_ESW_LINK_SPEED_AUTO:
         sSpeed = " AUTO  ";
         break;
      case NAI_ESW_LINK_SPEED_10:
         sSpeed = "  10   ";
         break;
      case NAI_ESW_LINK_SPEED_100:
         sSpeed = "  100  ";
         break;
      case NAI_ESW_LINK_SPEED_1G:
         sSpeed = "  1G   ";
         break;
      case NAI_ESW_LINK_SPEED_DISABLE:
         sSpeed = "DISABLE";
         break;
      default:
         sSpeed = " ERROR ";
         break;
      }

      check_status( naibrd_ESW_GetLinkSpeedStatus( cardIndex, module, port, &speedStatus ) );
      switch (speedStatus)
      {
      case NAI_ESW_LINK_SPEED_AUTO:
         sSpeedStatus = " AUTO  ";
         break;
      case NAI_ESW_LINK_SPEED_10:
         sSpeedStatus = "  10   ";
         break;
      case NAI_ESW_LINK_SPEED_100:
         sSpeedStatus = "  100  ";
         break;
      case NAI_ESW_LINK_SPEED_1G:
         sSpeedStatus = "  1G   ";
         break;
      case NAI_ESW_LINK_SPEED_DISABLE:
         sSpeedStatus = "DISABLE";
         break;
      default:
         sSpeedStatus = " ERROR ";
         break;
      }

      check_status( naibrd_ESW_GetLinkGigCapAdv( cardIndex, module, port, &gigabit ) );
      switch (gigabit)
      {
      case NAI_ESW_LINK_GIG_ADV_OFF:
         sGigabit = " OFF  ";
         break;
      case NAI_ESW_LINK_GIG_ADV_ON:
         sGigabit = "  ON  ";
         break;
      default:
         sGigabit = " ERROR";
         break;
      }

      check_status( naibrd_ESW_GetLinkMDIXMode( cardIndex, module, port, &mdix ) );
      switch (mdix)
      {
      case NAI_ESW_LINK_MDI_MODE:
         sMdix = " MDI  ";
         break;
      case NAI_ESW_LINK_MDIX_MODE:
         sMdix = " MDIX ";
         break;
      default:
         sMdix = " ERROR";
         break;
      }

      check_status( naibrd_ESW_GetBITStatus( cardIndex, module, port, &bitStatus ) );
      switch (bitStatus)
      {
      case NAI_ESW_LOOPBACK_PASSED:
         sBitStatus = "PASSED";
         break;
      case NAI_ESW_LOOPBACK_FAILED:
         sBitStatus = "FAILED";
         break;
      default:
         sBitStatus = "ERROR ";
         break;
      }

      printf( "%4d   %s   %s   %s               %s   %s   %s   %s   %s\n", port, sStatus, sDuplex, sDuplexStatus, sSpeed, sSpeedStatus, sGigabit, sMdix, sBitStatus );
   }
   printf( "\n" );
   printf( "All    0x%04X   0x%04X   0x%04X   Ports 1-4:  0x%04X    0x%04X    0x%04X   0x%04X   0x%04X\n", statusWord, duplexWord, duplexStatusWord, speedWord14, speedStatusWord14, gigabitWord, mdixWord, bitStatusWord );
   printf( "                                  Ports 5-8:  0x%04X    0x%04X\n", speedWord58, speedStatusWord58 );
   printf( "                                  Ports 9-12: 0x%04X    0x%04X\n", speedWord912, speedStatusWord912 );
}

/**************************************************************************************************************/
void ESW_DisplayVLANCfg( int32_t cardIndex, int32_t module, int32_t maxgroup )
{
   int32_t group;
   uint32_t vlanID;
   uint32_t vlanReturnStatus;
   bool_t vlanConfirm;
   nai_esw_vlan_ctrl_t vlanControlWord;
   bool_t vlanEnable;
   nai_esw_vlan_type_t vlanType;
   uint32_t vlanMembers;
   uint32_t vlanTaggingMembers;
   uint16_t vlanIPBits63to48;
   uint16_t vlanIPBits47to32;
   uint16_t vlanIPBits31to16;
   uint16_t vlanIPBits15to0;
   uint8_t IPv4Bits31to24;
   uint8_t IPv4Bits23to16;
   uint8_t IPv4Bits15to8;
   uint8_t IPv4Bits7to0;
   uint16_t IPv6Bits127to112;
   uint16_t IPv6Bits111to96;
   uint16_t IPv6Bits95to80;
   uint16_t IPv6Bits79to64;
   uint16_t vlanNetMaskBits63to48;
   uint16_t vlanNetMaskBits47to32;
   uint16_t vlanNetMaskBits31to16;
   uint16_t vlanNetMaskBits15to0;
   uint8_t IPv4NetBits31to24;
   uint8_t IPv4NetBits23to16;
   uint8_t IPv4NetBits15to8;
   uint8_t IPv4NetBits7to0;
   uint16_t IPv6NetBits127to112;
   uint16_t IPv6NetBits111to96;
   uint16_t IPv6NetBits95to80;
   uint16_t IPv6NetBits79to64;
   char* sVlanEnable;
   char* sVlanType;
   char* sVlanConfirm;

   printf( "\n\nESW VLAN Configuration:\n" );
   printf( "                                                                                          IPv4                          IPv6                        \n" );
   printf( "                 VLAN                                  Control                            Address/                      Address/                    \n" );
   printf( "                 Return                      Control   Register                           Network                       Network                     \n" );
   printf( "Group     ID     Status   Enabled    Type    Confirm   Value      Members   Tagging       Mask                          Mask                        \n" );
   printf( "----------------------------------------------------------------------------------------------------------------------------------------------------\n" );

   for ( group = 1; group <= maxgroup; group++ )
   {
      check_status( naibrd_ESW_GetVLANID( cardIndex, module, group, &vlanID ) );
      check_status( naibrd_ESW_GetVLANReturnStatus( cardIndex, module, group, &vlanReturnStatus ) );

      check_status( naibrd_ESW_GetVLANControlEnable( cardIndex, module, group, &vlanEnable ) );
      switch (vlanEnable)
      {
      case TRUE:
         sVlanEnable = " YES   ";
         break;
      case FALSE:
         sVlanEnable = " NO    ";
         break;
      default:
         sVlanEnable = " ERROR ";
         break;
      }

      check_status( naibrd_ESW_GetVLANControlType( cardIndex, module, group, &vlanType ) );
      switch (vlanType)
      {
      case NAI_ESW_VLAN_TYPE_PORT_BASED:
         sVlanType = " PORT ";
         break;
      case NAI_ESW_VLAN_TYPE_SUBNET_BASED:
         sVlanType = "SUBNET";
         break;
      default:
         sVlanType = "ERROR ";
         break;
      }

      check_status( naibrd_ESW_GetVLANControlConfirm( cardIndex, module, group, &vlanConfirm ) );
      switch (vlanConfirm)
      {
      case TRUE:
         sVlanConfirm = " YES   ";
         break;
      case FALSE:
         sVlanConfirm = "  NO   ";
         break;
      default:
         sVlanConfirm = " ERROR ";
         break;
      }

      check_status( naibrd_ESW_GetVLANControlWord( cardIndex, module, group, &vlanControlWord ) );
      check_status( naibrd_ESW_GetVLANMembers( cardIndex, module, group, &vlanMembers ) );
      check_status( naibrd_ESW_GetVLANMemberTagPkt( cardIndex, module, group, &vlanTaggingMembers ) );

      check_status( naibrd_ESW_GetVLANIPAddress( cardIndex, module, group, &vlanIPBits63to48, &vlanIPBits47to32, &vlanIPBits31to16, &vlanIPBits15to0 ) );
      IPv4Bits31to24 = (uint8_t)( ( vlanIPBits31to16 & 0xff00 ) >> 8 );
      IPv4Bits23to16 = (uint8_t)( vlanIPBits31to16 & 0xff );
      IPv4Bits15to8 = (uint8_t)( ( vlanIPBits15to0 & 0xff00 ) >> 8 );
      IPv4Bits7to0 = (uint8_t)( vlanIPBits15to0 & 0xff );
      IPv6Bits127to112 = vlanIPBits63to48;
      IPv6Bits111to96 = vlanIPBits47to32;
      IPv6Bits95to80 = vlanIPBits31to16;
      IPv6Bits79to64 = vlanIPBits15to0;

      check_status( naibrd_ESW_GetVLANNetworkMask( cardIndex, module, group, &vlanNetMaskBits63to48, &vlanNetMaskBits47to32, &vlanNetMaskBits31to16, &vlanNetMaskBits15to0 ) );
      IPv4NetBits31to24 = (uint8_t)( ( vlanNetMaskBits31to16 & 0xff00 ) >> 8 );
      IPv4NetBits23to16 = (uint8_t)( vlanNetMaskBits31to16 & 0xff );
      IPv4NetBits15to8 = (uint8_t)( ( vlanNetMaskBits15to0 & 0xff00 ) >> 8 );
      IPv4NetBits7to0 = (uint8_t)( vlanNetMaskBits15to0 & 0xff );
      IPv6NetBits127to112 = vlanNetMaskBits63to48;
      IPv6NetBits111to96 = vlanNetMaskBits47to32;
      IPv6NetBits95to80 = vlanNetMaskBits31to16;
      IPv6NetBits79to64 = vlanNetMaskBits15to0;

      printf( "%5d   0x%04X   0x%04X   %s   %s   %s    0x%04X    0x%04X    0x%04X    %03d.%03d.%03d.%03d   %04X:%04X:%04X:%04X:0000:0000:0000:0000\n", group, vlanID, vlanReturnStatus,
         sVlanEnable, sVlanType, sVlanConfirm, vlanControlWord, vlanMembers, vlanTaggingMembers, IPv4Bits31to24, IPv4Bits23to16, IPv4Bits15to8, IPv4Bits7to0, IPv6Bits127to112,
         IPv6Bits111to96, IPv6Bits95to80, IPv6Bits79to64 );
      printf( "                                                                                      %03d.%03d.%03d.%03d   %04X:%04X:%04X:%04X:0000:0000:0000:0000\n",
         IPv4NetBits31to24, IPv4NetBits23to16, IPv4NetBits15to8, IPv4NetBits7to0, IPv6NetBits127to112, IPv6NetBits111to96, IPv6NetBits95to80, IPv6NetBits79to64 );
   }
}

/**************************************************************************************************************/
bool_t CheckESWModule( int32_t *pCardIndex, int32_t *pModule, uint32_t *pModid, int32_t GetPortCount( int32_t cardIndex, int32_t module ) )
{
   bool_t bQuit = FALSE;
   int32_t MAX_MODULE, MAX_PORT;
   uint32_t modid, modver, modrev, special;
   int32_t cardIndex = -1, module = 1;

   bQuit = naiapp_query_CardIndex( naiapp_GetBoardCnt(), 0, &cardIndex );
   if (!bQuit)
   {
      check_status( naibrd_GetModuleCount( cardIndex, &MAX_MODULE ) );
      bQuit = naiapp_query_ModuleNumber( MAX_MODULE, 1, &module );
      if (!bQuit)
      {
         naibrd_GetModuleInfo( cardIndex, module, &modid, &modver, &modrev, &special );
         MAX_PORT = GetPortCount( cardIndex, module );

         if ( MAX_PORT <= 0 )
         {
            printf( " *** Module selection not recognized as valid module type for this application. ***\n\n" );
            bQuit = TRUE;
         }
         *pCardIndex = cardIndex;
         *pModule = module;
         *pModid = modid;
      }
   }
   return bQuit;
}

/**************************************************************************************************************/
bool_t GetPortNumber( int32_t cardIndex, int32_t module, int32_t MaxPort, int32_t DefPort, int32_t *Port )
{
   bool_t bQuit = FALSE;
   bool_t bContinue = TRUE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   MaxPort = naibrd_ESW_GetPortCount( cardIndex, module );

   if ( MaxPort > 1 )
   {
      while (bContinue)
      {
         printf( "\nPlease select port to access [default=%d]: ", DefPort );
         bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
         if (!bQuit)
         {
            if ( inputResponseCnt == 0 )
               *Port = DefPort;
            else
               *Port = (int32_t)atol( (const char*)inputBuffer );
            if ( ( *Port <= 0 ) || ( *Port > MaxPort ) )
               printf( "ERROR: Invalid port value.\n\n" );
            else
               bContinue = FALSE;
         }
         else
         {
            bContinue = FALSE;
         }
      }
   }
   else
      *Port = 1;
   return bQuit;
}

/**************************************************************************************************************/
bool_t GetVLANGroupNumber( int32_t cardIndex, int32_t module, int32_t MaxGroup, int32_t DefGroup, int32_t *Group )
{
   bool_t bQuit = FALSE;
   bool_t bContinue = TRUE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   MaxGroup = naibrd_ESW_GetVLANCount( cardIndex, module );

   if ( MaxGroup > 1 )
   {
      while (bContinue)
      {
         printf( "\nPlease select VLAN Group to access [default=%d]: ", DefGroup );
         bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
         if (!bQuit)
         {
            if ( inputResponseCnt == 0 )
               *Group = DefGroup;
            else
               *Group = (int32_t)atol( (const char*)inputBuffer );
            if ( ( *Group <= 0 ) || ( *Group > MaxGroup ) )
               printf( "ERROR: Invalid VLAN Group value.\n\n" );
            else
               bContinue = FALSE;
         }
         else
         {
            bContinue = FALSE;
         }
      }
   }
   else
      *Group = 1;
   return bQuit;
}

Help Bot

X