/**************************************************************
$Workfile:   pprofile.c  $
***************************************************************
**							    										
**	Filename    : pprofile.c	  		    									
**	Description : c source file defining the port profile management	 					
**	Author	    : jeya					    									
**	Date	    : 26 March 2001					 								
**	Notes	    :		  	   		    										
**  References  : host api document prepared by Tom.					    											 	
**	Revision History :				    										
**							    												
****************************************************************/

/***************************************************************
**
** FIRMWARE, Copyright (C) 2000-2002
** Ikanos Communication, Fremont, CA
** All rights reserved.
**
** The information and contents of this file are the
** proprietary information of Ikanos Communication and may not
** be disclosed or used without the formal written approval of
** Ikanos Communication
**
** $Revision: 1.2 $ 
** $Date: 2006/12/12 10:53:06 $
***************************************************************/

/* #includes */
#include <stdio.h>
#include <string.h>
#ifndef USE_VXWORKS /* IXDP425 */
#include <v2pthread.h>
#endif

#include "ipos.h"
#include "pprofile.h"
//#include "ecmd.h"
#include "bsp.h"
#include "oampdb.h"
#include "bmetl.h"
#include "dapi_define.h"

ipos_port_profile sDefPortProfile; /* default port profile */

ipos_port_profile sPortProfiles[MAX_PORT_PROFILES]; /* user defined variable port profiles */
int ProfileMapping [IPOS_MAX_PORTS+1];

static int pprofileSize = sizeof(ipos_port_profile);

#define MAX_AVAILABLE_CARR_SETS (4)

#define MAX_AVAILABLE_RFI_BANDS		(21)
static char  * availableRfiBands [MAX_AVAILABLE_RFI_BANDS] = {
    "1.810  - 1.825  MHz  : ANNEX F",
	"1.810  - 2.000  MHz  : ETSI, T1E1",
    "1.9075 - 1.9125 MHz  : ANNEX F",
	"3.500  - 3.575  MHz  : ANNEX F",
	"3.500  - 3.800  MHz  : ETSI",
    "3.500  - 4.000  MHz  : T1E1",
	"3.747  - 3.754  MHz  : ANNEX F",
	"3.791  - 3.805  MHz  : ANNEX F",
    "7.000  - 7.100  MHz  : ANNEX F, ETSI", 
	"7.000  - 7.300  MHz  : T1E1",
	"10.100 - 10.150 MHz  : ANNEX F, ETSI, T1E1",
	"14.000 - 14.350 MHz  : ANNEX F, ETSI, T1E1",
    "18.068 - 18.168 MHz  : ANNEX F, ETSI, T1E1",
    "1.800  - 1.825  MHz  : HAM Band 1",
    "3.500  - 3.550  MHz  : HAM Band 2",
    "3.790  - 3.800  MHz  : HAM Band 3",
  "1.800  - 1.810  MHz  : RFI Notch",
  "21.000 - 21.450 MHz  : ANNEX F, ETSI, T1E1",
  "24.890 - 24.990 MHz  : ANNEX F, ETSI, T1E1",
  "28.000 - 29.100 MHz  : ETSI",
  "28.000 - 29.700 MHz  : ANNEX F, T1E1"
};
   
U8 GetRfiMask [8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };

/* Local Prototype	*/
int getParameters(int ProfNum, int ParmType, int *ParmData);
void setPortOption (int profileNum);
void ife2_per_port_cfg(ipos_port_profile *tTempPtrPortProfile);

extern void configure_band(int profileNum, int is_cpe);
#ifdef CPE_40
void configure_ni(ipos_port_profile *pProfile);
#endif
/* function definitions */
/* 
Note : 
-----
If the user wants to set his own port profile, he should call setUserDefinedPortProfile ()
function by passing the profile number. Profile number should not exceed the MAX_PORT_PROFILES
#define value. If it increases, make sure to change the #define value too. After calling this
function, if the user wants to change very few parameters for this profile, he can then call
setPortParameter() function by passing the required port profile number, parameter type to be changed
& the parameter value. Then he can call getPortProfile () function by passing the same profile
number. The user can assign the tPtrPortProfile * returned by getPortProfile() function to
tPtrPortProfile of tPortParms structure. All these calls can be done in InitPortParms () function.
*/

void setDefaultPortMapping()
{
int i;

for (i=1;i<IPOS_MAX_PORTS+1;i++)
{
#ifdef VTU_O
	ProfileMapping[i]=1;
#else
	ProfileMapping[i]=2;
#endif
}

}
void displayRFIBandSetting (U8 band, char *binString)
{
	unsigned char and_mask;
	int i;
	and_mask = 0x80;
	for (i=0; i<8; i++) 
	{
		*binString++ = ((band & and_mask) ? '1' : '0');
		and_mask >>= 1;
	}
	*binString = '\0';
}
void getProfileMapping()
{

char *pProfileLoc = (char *)PORT_PROFILE_BASE;
//char chkStr[20];


   	pProfileLoc += ((MAX_PORT_PROFILES) * pprofileSize);

	//strcpy (&chkStr[0],pProfileLoc);

	if (strcmp (pProfileLoc, PROFILE_CHKSTR) == 0)
	{
		pProfileLoc +=0x10;   

		memcpy(&ProfileMapping[1], pProfileLoc, IPOS_MAX_PORTS*sizeof (int));

/*	FlashWrite ((unsigned char volatile*)pProfileLoc,
              (unsigned char*)&ProfileMapping[1], IPOS_MAX_PORTS*sizeof (int));
*/
	/*	for (i=1;i<IPOS_MAX_PORTS+1;i++)
		{
			printf ("\n i%i Prof %i",i,ProfileMapping[i]);
		}*/
	}
}

void setPprofileSize(int version)
{
	switch(version) {
		case 0:
		case 1:
		case 2:
	 		pprofileSize = 0;					
			break;
		case 3:
		case 4:
		case 5:
		case 6:
		case 7:	
			pprofileSize =	92;	
            break;
        case 8:
        case 9:
        case 10:
        case 11:
        case 12:
            pprofileSize =	96;
        default:            
			break;
	}
}

int get_notchBandConfig (ipos_port_profile * portProfile)
{
 	int threeBand = (portProfile->PortProvParms.BandPlan != BP3_998_4);
	int	selNum;
	
	switch (portProfile->PortProvParms.NumRFIBand)
  	{
    	case 0:  
			selNum = 1;
			break;
    	case 1:
			selNum = 4;
			if (portProfile->PortProvParms.Band1Start == 0)
			{
				if (threeBand)
			 	{
					if (portProfile->PortProvParms.Band1Stop == STOP_BAN_640K_3BAND)
						selNum = 2;
					else
					{
						if (portProfile->PortProvParms.Band1Stop == STOP_BAN_1100K_3BAND)
							selNum = 3;
					}
				}
        		else
        		{
         	 		if (portProfile->PortProvParms.Band1Stop == STOP_BAN_640K_4BAND)
          			{  
						selNum = 2;
          			}
		  			else
          			{
						if (portProfile->PortProvParms.Band1Stop == STOP_BAN_1100K_4BAND)
            				selNum = 3;
          			}
        		}
      		}
      		break;
    	default:
			selNum = 4;
			break;  
  	}
	
	return(selNum);	
}

void setDefaultNewProfileVal(int version)
{
	int 				bandModifier;
	ipos_port_profile 	*portProfile;
	int profilenum;

		
	switch(version) {
		case 0:
		case 1:
		case 2:
	 	case 3:
		case 4:
		case 5:
		case 6:
			// add new members' default value here.
		    for (profilenum=0;profilenum<MAX_PORT_PROFILES;profilenum++)
		    {
			    portProfile = &(sPortProfiles[profilenum]);

			    bandModifier = get_notchBandConfig (portProfile);
			
			    portProfile->BandMod.bandModifier = ((bandModifier&0xf)<<4)|(bandModifier&0xf);				
					
			    if(bandModifier == 2 || bandModifier == 3) // from now on use portProfile->BandMod.bandModifier to turn off the tones instead of notch band
			    {
			   	    portProfile->PortProvParms.NumRFIBand = 0;
  				    portProfile->PortProvParms.Band1Start = portProfile->PortProvParms.Band1Stop = 0;
			    }
		    }


		    for (profilenum=0;profilenum<MAX_PORT_PROFILES;profilenum++)
		    {
			    portProfile = &(sPortProfiles[profilenum]);

			    portProfile->OptionParms.PortOption=0;
			    portProfile->OptionParms.Reserved1=0;
			    portProfile->OptionParms.Reserved2=0;
			    portProfile->OptionParms.Reserved3=0;
                
                // ife 2 board specific configuration
                portProfile->IFE_BRD_CFG.pwrMode = 0; // 8.5 dbm mode
                portProfile->IFE_BRD_CFG.rxPathFilterMode = 0; // use current default setting
                portProfile->IFE_BRD_CFG.txPathFilterMode = 0; // use internal tx filter
		    }
			break;
		case 7:

		    for (profilenum=0;profilenum<MAX_PORT_PROFILES;profilenum++)
		    {
			    portProfile = &(sPortProfiles[profilenum]);

			    portProfile->OptionParms.PortOption=0;
			    portProfile->OptionParms.Reserved1=0;
			    portProfile->OptionParms.Reserved2=0;
			    portProfile->OptionParms.Reserved3=0;
                // ife 2 board specific configuration
                portProfile->IFE_BRD_CFG.pwrMode = 0; // 8.5 dbm mode
                portProfile->IFE_BRD_CFG.rxPathFilterMode = 0; // use current default setting
                portProfile->IFE_BRD_CFG.txPathFilterMode = 0; // use internal tx filter
		    }
			break;

        default:     
		for (profilenum=0;profilenum<MAX_PORT_PROFILES;profilenum++)
		    {
			    portProfile = &(sPortProfiles[profilenum]);			    
	                // ife 2 board specific configuration
 	  	             portProfile->IFE_BRD_CFG.pwrMode = 0; // 8.5 dbm mode
  		             portProfile->IFE_BRD_CFG.rxPathFilterMode = 0; // use current default setting
     			     portProfile->IFE_BRD_CFG.txPathFilterMode = 0; // use internal tx filter
		    }       
			break;			
	}
}

/********************************************************************************\
	Name 	   : setPortParameter							 
	Purpose    : To set a specific port parameter in a port profile by passing the
					port parameter value.		

	Parameters : 
	no		Name		Type				Description
	--		----		----				-----------
	1. bProfileNum		U8			Port Profile Number
	2. bPortCmd			U8			Port Command ( PROVISION / START / STOP / RESET / DESTROY....)
	3. bParamType		U8			Parameter Type to set 
	4. cPtrParamVal		U8 *			Parameter Value to set

	Return	   : 
	Type				Description
	----				-----------
	eProfileMgmtRv		if success, PROFILE_MGMT_REQ_SUCCESS
						if error, error codes like WRONG_PROFILE_NUMBER, 
							WRONG_PARAM_VALUE			
\********************************************************************************/

eProfileMgmtRv setPortParameter (U8 bProfileNum, U8 bPortCmd, U8 bParamType, U32 *cPtrParamVal)
{
	ipos_port_profile *tTempPtrPortProfile;

//    EventLog("\nsetPortParameter ProfileNum %i, bPortCmd %x, ParmType 0x%x",bProfileNum,bPortCmd,bParamType);

	if (bProfileNum >= MAX_PORT_PROFILES)
	{
		printf ("\nWrong Profile number! Unable to process the request!");
		return WRONG_PROFILE_NUMBER;
	}

	tTempPtrPortProfile = &sPortProfiles[bProfileNum];

	switch (bPortCmd)
	{
            case PORT_PROVISION:
               switch (bParamType)
			    {
               case INTERLEAVED_PERCENTAGE:
                    if ((U16)(*cPtrParamVal) > 100)
                    {
                        printf("\n Wrong value %d is greater than 100 percentage", (U16)(*cPtrParamVal));
                        return WRONG_PARAM_VALUE;
                    }
                    else
					{
						tTempPtrPortProfile->PortProvParms.InterleavedPercentage = (U16)(*cPtrParamVal);
			
						if (tTempPtrPortProfile->PortProvParms.InterleavedPercentage==100)
						{
							// Fast mode change to default values
							if (tTempPtrPortProfile->PortProvParms.UpstreamMaxRateFast==0)
								tTempPtrPortProfile->PortProvParms.UpstreamMaxRateFast=3125;
							if (tTempPtrPortProfile->PortProvParms.UpstreamMinRateFast==0)
								tTempPtrPortProfile->PortProvParms.UpstreamMinRateFast=0xa;
							if (tTempPtrPortProfile->PortProvParms.UpstreamMinRateSlow!=0)
								tTempPtrPortProfile->PortProvParms.UpstreamMinRateSlow=0;
							if (tTempPtrPortProfile->PortProvParms.UpstreamMaxRateSlow!=0)
								tTempPtrPortProfile->PortProvParms.UpstreamMaxRateSlow=0;
#ifdef VTU_O
							if (tTempPtrPortProfile->PortProvParms.DownstreamMaxRateFast==0)
								tTempPtrPortProfile->PortProvParms.DownstreamMaxRateFast=3125;
							if (tTempPtrPortProfile->PortProvParms.DownstreamMinRateFast==0)
								tTempPtrPortProfile->PortProvParms.DownstreamMinRateFast=0xa;
							if (tTempPtrPortProfile->PortProvParms.DownstreamMinRateSlow!=0)
								tTempPtrPortProfile->PortProvParms.DownstreamMinRateSlow=0;
							if (tTempPtrPortProfile->PortProvParms.DownstreamMaxRateSlow!=0)
								tTempPtrPortProfile->PortProvParms.DownstreamMaxRateSlow=0;

#else
							if (tTempPtrPortProfile->PortProvParms.DownstreamMaxRateSlow==0)
								tTempPtrPortProfile->PortProvParms.DownstreamMaxRateSlow=3125;
							if (tTempPtrPortProfile->PortProvParms.DownstreamMinRateSlow==0)
								tTempPtrPortProfile->PortProvParms.DownstreamMinRateSlow=0xa;
							if (tTempPtrPortProfile->PortProvParms.DownstreamMinRateFast!=0)
								tTempPtrPortProfile->PortProvParms.DownstreamMinRateFast=0;
							if (tTempPtrPortProfile->PortProvParms.DownstreamMaxRateFast!=0)
								tTempPtrPortProfile->PortProvParms.DownstreamMaxRateFast=0;
#endif

						}
						else if (tTempPtrPortProfile->PortProvParms.InterleavedPercentage==0)
						{
							// Interleaved mode change to default values
							if (tTempPtrPortProfile->PortProvParms.UpstreamMaxRateSlow==0)
								tTempPtrPortProfile->PortProvParms.UpstreamMaxRateSlow=3125;
							if (tTempPtrPortProfile->PortProvParms.UpstreamMinRateSlow==0)
								tTempPtrPortProfile->PortProvParms.UpstreamMinRateSlow=0xa;
							if (tTempPtrPortProfile->PortProvParms.UpstreamMinRateFast!=0)
								tTempPtrPortProfile->PortProvParms.UpstreamMinRateFast=0;
							if (tTempPtrPortProfile->PortProvParms.UpstreamMaxRateFast!=0)
								tTempPtrPortProfile->PortProvParms.UpstreamMaxRateFast=0;

							if (tTempPtrPortProfile->PortProvParms.DownstreamMaxRateSlow==0)
								tTempPtrPortProfile->PortProvParms.DownstreamMaxRateSlow=3125;
							if (tTempPtrPortProfile->PortProvParms.DownstreamMinRateSlow==0)
								tTempPtrPortProfile->PortProvParms.DownstreamMinRateSlow=0xa;
							if (tTempPtrPortProfile->PortProvParms.DownstreamMinRateFast!=0)
								tTempPtrPortProfile->PortProvParms.DownstreamMinRateFast=0;
							if (tTempPtrPortProfile->PortProvParms.DownstreamMaxRateFast!=0)
								tTempPtrPortProfile->PortProvParms.DownstreamMaxRateFast=0;

						}
					}
					break;

				case UPSTREAM_MAX_RATE_FAST:
					
					if ((*(unsigned long *)cPtrParamVal) > 0xc35) /* 200 Mbps */
                        return WRONG_PARAM_VALUE;
                    else
					{
						if ((*(unsigned long *)cPtrParamVal) <
								tTempPtrPortProfile->PortProvParms.UpstreamMinRateFast)
						{
						// If min rate exceeds max rate, set min rate to equal max rate
						tTempPtrPortProfile->PortProvParms.UpstreamMinRateFast=*(unsigned long *)cPtrParamVal;
				
						}

						tTempPtrPortProfile->PortProvParms.UpstreamMaxRateFast = *(unsigned long *)cPtrParamVal;						

					}
					break;

				case UPSTREAM_MIN_RATE_FAST:
					if ((*(unsigned long *)cPtrParamVal) > 0xc35) /* 200 Mbps */
                        return WRONG_PARAM_VALUE;
                    else
					{
						if ((*(unsigned long *)cPtrParamVal) >
								tTempPtrPortProfile->PortProvParms.UpstreamMaxRateFast)
						{
						tTempPtrPortProfile->PortProvParms.UpstreamMaxRateFast=*(unsigned long *)cPtrParamVal;
						}

						tTempPtrPortProfile->PortProvParms.UpstreamMinRateFast = *(unsigned long *)cPtrParamVal;

					}

					break;

				case UPSTREAM_MAX_RATE_SLOW: 
					if ((*(unsigned long *)cPtrParamVal) > 0xc35) /* 200 Mbps */
                        return WRONG_PARAM_VALUE;
                    else
					{
						if ((*(unsigned long *)cPtrParamVal) <
								tTempPtrPortProfile->PortProvParms.UpstreamMinRateSlow)
						{
						tTempPtrPortProfile->PortProvParms.UpstreamMinRateSlow=*(unsigned long *)cPtrParamVal;
						}

						tTempPtrPortProfile->PortProvParms.UpstreamMaxRateSlow = *(unsigned long *)cPtrParamVal;
					}

					break;

				case UPSTREAM_MIN_RATE_SLOW:
					if ((*(unsigned long *)cPtrParamVal) > 0xc35) /* 200 Mbps */
                        return WRONG_PARAM_VALUE;
                    else
					{
						if ((*(unsigned long *)cPtrParamVal) >
								tTempPtrPortProfile->PortProvParms.UpstreamMaxRateSlow)
						{
						tTempPtrPortProfile->PortProvParms.UpstreamMaxRateSlow=*(unsigned long *)cPtrParamVal;

						}

						tTempPtrPortProfile->PortProvParms.UpstreamMinRateSlow = *(unsigned long *)cPtrParamVal;
					}

					break;

				case UPSTREAM_MAX_INTER_DELAY:
                    if ((U8)(*cPtrParamVal) > 100) /* max 100 milli seconds ? */
					{
						printf ("\nWrong value %d for downstream max inter delay", (U8)(*cPtrParamVal));	
						return WRONG_PARAM_VALUE;
					}
                    else
						tTempPtrPortProfile->PortProvParms.UpstreamMaxInterDelay = (U8)(*cPtrParamVal);
                    break;	

				case DOWNSTREAM_MAX_RATE_FAST:
					if ((*(unsigned long *)cPtrParamVal) > 0xc35) /* 200 Mbps */
                        return WRONG_PARAM_VALUE;
                    else
					{
						if ((*(unsigned long *)cPtrParamVal) <
								tTempPtrPortProfile->PortProvParms.DownstreamMinRateFast)
						{

						tTempPtrPortProfile->PortProvParms.DownstreamMinRateFast=*(unsigned long *)cPtrParamVal;

						}

						tTempPtrPortProfile->PortProvParms.DownstreamMaxRateFast = *(unsigned long *)cPtrParamVal;
					}

					break;

				case DOWNSTREAM_MIN_RATE_FAST:
					if ((*(unsigned long *)cPtrParamVal) > 0xc35) /* 200 Mbps */
						return WRONG_PARAM_VALUE;
                    else
					{
						if ((*(unsigned long *)cPtrParamVal) >
								tTempPtrPortProfile->PortProvParms.DownstreamMaxRateFast)
						{

						tTempPtrPortProfile->PortProvParms.DownstreamMaxRateFast=*(unsigned long *)cPtrParamVal;

						}

						tTempPtrPortProfile->PortProvParms.DownstreamMinRateFast = *(unsigned long *)cPtrParamVal;
					}
					break;

				case DOWNSTREAM_MAX_RATE_SLOW:
					if ((*(unsigned long *)cPtrParamVal) > 0xc35) /* 200 Mbps */
                        return WRONG_PARAM_VALUE;
                    else
					{
						if ((*(unsigned long *)cPtrParamVal) <
								tTempPtrPortProfile->PortProvParms.DownstreamMinRateSlow)
						{
						tTempPtrPortProfile->PortProvParms.DownstreamMinRateSlow=*(unsigned long *)cPtrParamVal;

						}
						else
							tTempPtrPortProfile->PortProvParms.DownstreamMaxRateSlow = *(unsigned long *)cPtrParamVal;
					}
					break;

				case DOWNSTREAM_MIN_RATE_SLOW:
					if ((*(unsigned long *)cPtrParamVal) > 0xc35) /* 200 Mbps */
                        return WRONG_PARAM_VALUE;
                    else
					{
						if ((*(unsigned long *)cPtrParamVal) >
								tTempPtrPortProfile->PortProvParms.DownstreamMaxRateSlow)
						{
						tTempPtrPortProfile->PortProvParms.DownstreamMaxRateSlow=*(unsigned long *)cPtrParamVal;

						}

						tTempPtrPortProfile->PortProvParms.DownstreamMinRateSlow = *(unsigned long *)cPtrParamVal;
					}
					break;

				case DOWNSTREAM_MAX_INTER_DELAY:
                    if ((U8)(*cPtrParamVal) > 100) /* max 100 milli seconds ? */
					{
						printf ("\nWrong value %d for downstream max inter delay", (U8)(*cPtrParamVal));	
						return WRONG_PARAM_VALUE;
					}
					else
						tTempPtrPortProfile->PortProvParms.DownstreamMaxInterDelay = (U8)(*cPtrParamVal);
					
					break;
                case DS_TARGET_NOISE_MARGIN:
                    if ((U16)(*cPtrParamVal) > 62) /* max 31dB : 1 for 0.5dB */
                    {
                        printf ("\nWrong value %d for Noise Margin. Should be between 0-62", (U16)(*cPtrParamVal));
                        return WRONG_PARAM_VALUE;
                    }
                    else
                        tTempPtrPortProfile->PortProvParms.DsTargetNoiseMargin = (U16)(*cPtrParamVal);
                    break;
    
                case MIN_NOISE_MARGIN:
                    if ((U16)(*cPtrParamVal) > 62) /* max 31dB : 1 for 0.5dB */
                    {
                        printf ("\nWrong value %d for Noise Margin. Should be between 0-62", (U16)(*cPtrParamVal));	
                        return WRONG_PARAM_VALUE;
                    }
                    else
    
                    tTempPtrPortProfile->PortProvParms.MinNoiseMargin = (U16)(*cPtrParamVal);					
                    break;

                case US_TARGET_NOISE_MARGIN:
                    if ((U16)(*cPtrParamVal) > 62) /* max 31dB : 1 for 0.5dB */
                    {
                        printf ("\nWrong value %d for Noise Margin. Should be between 0-62", (U16)(*cPtrParamVal));	
                        return WRONG_PARAM_VALUE;
                    }
                    else
                        tTempPtrPortProfile->PortProvParms.UsTargetNoiseMargin = (U16)(*cPtrParamVal);										
                    break;

    

                case INTERLEAVED_CHANNEL:
    
                    if ((U8)(*cPtrParamVal) > MAX_CHANNEL_NUMBER)
                    {
                        printf ("\nWrong value %d for interleaved channel", (U8)(*cPtrParamVal));	
                        return WRONG_PARAM_VALUE;
                    }
                    else{
                        tTempPtrPortProfile->PortProvParms.InterleavedChannel = (U8)(*cPtrParamVal);	
                    printf ("\n changed value %x",(U8)(*cPtrParamVal));}
                    break;
    
                case FAST_CHANNEL:
                    if ((U8)(*cPtrParamVal) > MAX_CHANNEL_NUMBER)
                    {
                        printf ("\nWrong value %d for fast channel", (U8)(*cPtrParamVal));	
                        return WRONG_PARAM_VALUE;
                    }
                    else
                        tTempPtrPortProfile->PortProvParms.FastChannel = (U8)(*cPtrParamVal);
                    break;
    
                case LINE_TYPE:
                    if ((U8)(*cPtrParamVal) > 0xFF)
                    {
                        printf ("\nWrong value %d for line type", (U8)(*cPtrParamVal));	
                        return WRONG_PARAM_VALUE;
                    }
                    else
                        tTempPtrPortProfile->PortProvParms.LineType = (U8)(*cPtrParamVal);
    
                    break;
    
                case DSL_MODE:
                    if ((U8)(*cPtrParamVal) > MAX_DSL_MODES)
                    {
                        printf ("\nWrong value %d for dsl mode", (U8)(*cPtrParamVal));	
                        return WRONG_PARAM_VALUE;
                    }
                    else
                        tTempPtrPortProfile->PortProvParms.DslMode = (U8)(*cPtrParamVal);
    
                    break;
    
                case RATE_ADAPTATION_MODE:
                    if ((U8)(*cPtrParamVal) > 1)
                    {
                        printf ("\nWrong value %d for rate adaptation mode", (U8)(*cPtrParamVal));	
                        return WRONG_PARAM_VALUE;
                    }
                    else
                        tTempPtrPortProfile->PortProvParms.RateAdaptationMode = (U8)(*cPtrParamVal);
    
                    break;

                case NUM_PARITY_FAST:
                    if ((U8)(*cPtrParamVal) > 16) /* max 16 parity bytes  */
					{
						printf ("\nWrong value %d for number of parity bytes", (U8)(*cPtrParamVal));	
						return WRONG_PARAM_VALUE;
					}
					else
						tTempPtrPortProfile->PortProvParms.NumParityFast = (U8)(*cPtrParamVal);

					break;

				case NUM_PARITY_SLOW:
                    if ((*(U8 *)cPtrParamVal) > 16) /* max 16 parity bytes  */
					{
						printf ("\nWrong value %d for number of parity bytes", (U8)(*cPtrParamVal));	
						return WRONG_PARAM_VALUE;
					}
					else
						tTempPtrPortProfile->PortProvParms.NumParitySlow = (U8)(*cPtrParamVal);

					break;

                case BAND_PLAN:
                    printf("\n Band Plan.. value = %d", (U8)(*cPtrParamVal));
                    /* check cPtrParamVal if required */
                    tTempPtrPortProfile->PortProvParms.BandPlan = (U8)(*cPtrParamVal);					
                    break;

                case NUM_RFI_BAND:
                    /* check cPtrParamVal if required */
                    tTempPtrPortProfile->PortProvParms.NumRFIBand = (U8)(*cPtrParamVal);					
                    break;

                case BAND_1_START:
                   /* check cPtrParamVal if required */
                   tTempPtrPortProfile->PortProvParms.Band1Start = (U16)(*cPtrParamVal);					
                   break;

                case BAND_1_STOP:
                     /* check cPtrParamVal if required */
                    tTempPtrPortProfile->PortProvParms.Band1Stop = (U16)(*cPtrParamVal);					
                    break;

                case BAND_2_START:
                    /* check cPtrParamVal if required */
                    tTempPtrPortProfile->PortProvParms.Band2Start = (U16)(*cPtrParamVal);					
                    break;

                case BAND_2_STOP:
                    /* check cPtrParamVal if required */
                    tTempPtrPortProfile->PortProvParms.Band2Stop = (U16)(*cPtrParamVal);					
                    break;

                case BAND_3_START:
                    /* check cPtrParamVal if required */
                    tTempPtrPortProfile->PortProvParms.Band3Start = (U16)(*cPtrParamVal);					
                    break;

                case BAND_3_STOP:
                    /* check cPtrParamVal if required */
                    tTempPtrPortProfile->PortProvParms.Band3Stop = (U16)(*cPtrParamVal);					
                    break;

                case BAND_4_START:
                    /* check cPtrParamVal if required */
                    tTempPtrPortProfile->PortProvParms.Band4Start = (U16)(*cPtrParamVal);					
                    break;

                case BAND_4_STOP:
                    /* check cPtrParamVal if required */
                    tTempPtrPortProfile->PortProvParms.Band4Stop = (U16)(*cPtrParamVal);					
                    break;

                case BAND_5_START:
                    /* check cPtrParamVal if required */
                    tTempPtrPortProfile->PortProvParms.Band5Start = (U16)(*cPtrParamVal);					
                    break;

                case BAND_5_STOP:
                    /* check cPtrParamVal if required */
                    tTempPtrPortProfile->PortProvParms.Band5Stop = (U16)(*cPtrParamVal);					
                    break;

                case UPSTREAM_MIN_PROTECTION:
                    tTempPtrPortProfile->PortProvParms.UsMinProtection = (U8)(*cPtrParamVal);
    
                    break;
                case DOWNSTREAM_MIN_PROTECTION:
                    tTempPtrPortProfile->PortProvParms.DsMinProtection = (U8)(*cPtrParamVal);
    
                    break;
#ifdef CPE_40
                case NETWORK_FRAMING_MODE:
      
                    tTempPtrPortProfile->PortProvParms.framingmode = (U8)(*cPtrParamVal);
                 break;
#endif
				default:
					printf ("\nUnrecognized Port Provision Parameter %d", bParamType);
					return WRONG_PARAM_VALUE;
			}
				
			break;
			

		case PORT_RESET:
			switch (bParamType)
			{
				case PORT_START_PARAM:
					if (((U8)(*cPtrParamVal) != 0) && ((U8)(*cPtrParamVal) != 1) && 
						((U8)(*cPtrParamVal) != 4) && ((U8)(*cPtrParamVal) != 5))
					{
						printf ("\nWrong value %d for port reset parameter", (U8)(*cPtrParamVal));	
						return WRONG_PARAM_VALUE;
					}
					else
						tTempPtrPortProfile->PortStartResetParms.PortStartParm = (U8)(*cPtrParamVal);

					break;	

				default:
					printf ("\nUnrecognized Port Reset Parameter %d", bParamType);
					return WRONG_PARAM_VALUE;
			}			
			break;

		default :
			printf ("\nunrecognized port command %d!", bPortCmd);
			return WRONG_PARAM_VALUE;
	}

	updateFlashProf();

	return (PROFILE_MGMT_REQ_SUCCESS);
}

/********************************************************************************\
	Name 	   : getDefaultPortProfile							 
	Purpose    : To get the default port profile.	
	Parameters : None
	Return	   : 
	Type				Description
	----				-----------
	ipos_port_profile *		ptr to ipos_port_profile typedef structure, pointing to the default 
							port profile
\********************************************************************************/
ipos_port_profile *getDefaultPortProfile (void)
{
	return (&sDefPortProfile);
}

/********************************************************************************\
	Name 	   : getPortProfile							 
	Purpose    : To get the port profile by passing the port profile number.	
	Parameters : 
	no		Name		Type			Description
	--		----		----			-----------
	1. bProfileNum		U8		Port Profile Number
	
	Return	   : 
	Type				Description
	----				-----------
	ipos_port_profile *		ptr to ipos_port_profile typedef structure, pointing to the 
							port profile
\********************************************************************************/
ipos_port_profile *getPortProfile (U8 bProfileNum)
{
	if (bProfileNum >= MAX_PORT_PROFILES)
	{
		printf ("\nWrong Profile number! Unable to process the request!");
		return NULL;
	}
	else
		return (&sPortProfiles[bProfileNum]);
}

/********************************************************************************\
	Name 	   : setDefaultPortProfile							 
	Purpose    : To set the default port profile by assigning default values to all
					the port parameters.User should call this function, before 
					initializing any of the ports. Then the user can assign this 
					default port profile to the corresponding port.	
	Parameters : None
	Return	   : void
\********************************************************************************/
void setDefaultPortProfile (void)
{
	U8 index;

	sDefPortProfile.PortProfileNum=0;

	/* Port Provision parameters */
	sDefPortProfile.PortProvParms.InterleavedChannel = 1; /* 0 - 63 */
	sDefPortProfile.PortProvParms.FastChannel = 0; /* 0 - 63 */		
	sDefPortProfile.PortProvParms.LineType = 0x81; /* automatic */	
	sDefPortProfile.PortProvParms.DslMode = 5; /* Both fast and interleaved/slow channel exists */
	sDefPortProfile.PortProvParms.RateAdaptationMode = 1; /* Startup */	
	sDefPortProfile.PortProvParms.InterleavedPercentage = 0;
	sDefPortProfile.PortProvParms.UpstreamMaxRateFast = 0; /* x64 kbps */ 
	sDefPortProfile.PortProvParms.UpstreamMinRateFast = 0; /* x64 kbps */
	sDefPortProfile.PortProvParms.UpstreamMaxRateSlow = 3125; /* x64 kbps */
	sDefPortProfile.PortProvParms.UpstreamMinRateSlow = 1;  /* x64 kbps */	
	sDefPortProfile.PortProvParms.UpstreamMaxInterDelay = 4; /* milli seconds 0.5 ms */
	sDefPortProfile.PortProvParms.DownstreamMaxRateFast = 0; /* x64 kbps */
	sDefPortProfile.PortProvParms.DownstreamMinRateFast = 0; /* x64 kbps */
	sDefPortProfile.PortProvParms.DownstreamMaxRateSlow = 3125; /* x64 kbps */
	sDefPortProfile.PortProvParms.DownstreamMinRateSlow = 1; /* x64 kbps */
	sDefPortProfile.PortProvParms.DownstreamMaxInterDelay = 4; /* milli seconds 0.5 ms */
	sDefPortProfile.PortProvParms.NumParityFast = 4; /* no.of parity bytes */
	sDefPortProfile.PortProvParms.NumParitySlow = 4; /* no.of parity bytes */
	sDefPortProfile.PortProvParms.UsTargetNoiseMargin = 14; /* 0 - 31.0 db, steps of 0.5 db */
	sDefPortProfile.PortProvParms.DsTargetNoiseMargin = 14; /* 0 - 31 db, steps of 0.5 db */
	sDefPortProfile.PortProvParms.MinNoiseMargin = 10; /* 0 - 31 db, steps of 0.5 db */
	sDefPortProfile.PortProvParms.BandPlan=BP2_998_3;
    sDefPortProfile.PortProvParms.NumRFIBand=0;
	    /* Set these if NumRFIBand>0
    tTempPtrPortProfile->PortProvParms.Band1Start=
    tTempPtrPortProfile->PortProvParms.Band1Stop...*/

	sDefPortProfile.PortProvParms.Band1Start=0;
	sDefPortProfile.PortProvParms.Band1Stop=0;
    	sDefPortProfile.PortProvParms.Band2Start=0;
	sDefPortProfile.PortProvParms.Band2Stop=0;
	sDefPortProfile.PortProvParms.Band3Start=0;
	sDefPortProfile.PortProvParms.Band3Stop=0;
	sDefPortProfile.PortProvParms.Band4Start=0;
	sDefPortProfile.PortProvParms.Band4Stop=0;
	sDefPortProfile.PortProvParms.Band5Start=0;
	sDefPortProfile.PortProvParms.Band5Stop=0;

    sDefPortProfile.PortProvParms.RFIBand1 = 0;
    sDefPortProfile.PortProvParms.RFIBand2 = 0;
    sDefPortProfile.PortProvParms.RFIBand3 = 0;
    sDefPortProfile.PortProvParms.RFIBand4 = 0;
    sDefPortProfile.PortProvParms.RFIBand5 = 0;
    sDefPortProfile.PortProvParms.DsMinProtection=0;
    sDefPortProfile.PortProvParms.UsMinProtection=0;
#ifdef CPE_40
#ifdef INI_SUPPORT
    sDefPortProfile.PortProvParms.framingmode=0x80;
#else
    sDefPortProfile.PortProvParms.framingmode=0;
#endif
#endif

    sDefPortProfile.OptionParms.PortOption = 1;
	sDefPortProfile.OptionParms.Reserved1 = 0;
	sDefPortProfile.OptionParms.Reserved2 = 0;
	sDefPortProfile.OptionParms.Reserved3 = 0;
	/* Port Instantiate paramaters */

	/* Port Start Reset parameters */
	sDefPortProfile.PortStartResetParms.PortStartParm = 0; /* StartMode - Port Initiate, 
	 													   RateAdaptationMode - Fixed */	

	/* Port Stop parameters */
	sDefPortProfile.PortStopParms.PortStopParm = 1; /* graceful stop */

	sDefPortProfile.BandMod.bandModifier = 0x33;		//optional band off

	sDefPortProfile.IFE_BRD_CFG.pwrMode = 0;
 	sDefPortProfile.IFE_BRD_CFG.rxPathFilterMode = 0;
    	sDefPortProfile.IFE_BRD_CFG.txPathFilterMode = 0;
	/* Port Destroy parameters */

	/* initialize the other port profiles with default values */
	for (index = 0; index < MAX_PORT_PROFILES; index++)
	{
		memcpy((U8 *)&sPortProfiles[index], (U8 *)&sDefPortProfile, sizeof (ipos_port_profile));
		sPortProfiles[index].PortProfileNum = index+1;
	}

	return; 
}

void setCpeDefaultPortProfile (int profilenum)
{
	ipos_port_profile *tTempPtrPortProfile;

	tTempPtrPortProfile = &sPortProfiles[profilenum];

	tTempPtrPortProfile->PortProfileNum=profilenum;

	/* Port Provision parameters */
	tTempPtrPortProfile->PortProvParms.InterleavedChannel = 1; /* 0 - 63 */
	tTempPtrPortProfile->PortProvParms.FastChannel = 0; /* 0 - 63 */		
	tTempPtrPortProfile->PortProvParms.LineType = 0x81; /* automatic */	
	tTempPtrPortProfile->PortProvParms.DslMode = 5; /* Both fast and interleaved/slow channel exists */
	tTempPtrPortProfile->PortProvParms.RateAdaptationMode = 1; /* Startup */	
	tTempPtrPortProfile->PortProvParms.InterleavedPercentage = 0;
	tTempPtrPortProfile->PortProvParms.UpstreamMaxRateFast = 0; /* x64 kbps */ 
	tTempPtrPortProfile->PortProvParms.UpstreamMinRateFast = 0; /* x64 kbps */
	tTempPtrPortProfile->PortProvParms.UpstreamMaxRateSlow = 3125; /* x64 kbps */
	tTempPtrPortProfile->PortProvParms.UpstreamMinRateSlow = 1;  /* x64 kbps */	
	tTempPtrPortProfile->PortProvParms.UpstreamMaxInterDelay = 4; /* milli seconds 0.5ms */
	tTempPtrPortProfile->PortProvParms.DownstreamMaxRateFast = 0; /* x64 kbps */
	tTempPtrPortProfile->PortProvParms.DownstreamMinRateFast = 0; /* x64 kbps */
	tTempPtrPortProfile->PortProvParms.DownstreamMaxRateSlow = 3125; /* x64 kbps */
	tTempPtrPortProfile->PortProvParms.DownstreamMinRateSlow = 1; /* x64 kbps */
	tTempPtrPortProfile->PortProvParms.DownstreamMaxInterDelay = 4; /* milli seconds 0.5ms */
	tTempPtrPortProfile->PortProvParms.NumParityFast = 4; /* no.of parity bytes */
	tTempPtrPortProfile->PortProvParms.NumParitySlow = 4; /* no.of parity bytes */
	tTempPtrPortProfile->PortProvParms.UsTargetNoiseMargin = 12; /* 0 - 31.0 db, steps of 0.5 db */
	tTempPtrPortProfile->PortProvParms.DsTargetNoiseMargin = 12; /* 0 - 31 db, steps of 0.5 db */
	tTempPtrPortProfile->PortProvParms.MinNoiseMargin = 10; /* 0 - 31 db, steps of 0.5 db */
	tTempPtrPortProfile->PortProvParms.BandPlan=BP3_998_4;
    tTempPtrPortProfile->PortProvParms.NumRFIBand=0;
	    /* Set these if NumRFIBand>0*/
    tTempPtrPortProfile->PortProvParms.Band1Start=0;
    tTempPtrPortProfile->PortProvParms.Band1Stop= 0;
    tTempPtrPortProfile->PortProvParms.Band2Start=0;
    tTempPtrPortProfile->PortProvParms.Band2Stop=0;
    tTempPtrPortProfile->PortProvParms.Band3Start=0;
    tTempPtrPortProfile->PortProvParms.Band3Stop=0;
    tTempPtrPortProfile->PortProvParms.Band4Start=0;
    tTempPtrPortProfile->PortProvParms.Band4Stop=0;
    tTempPtrPortProfile->PortProvParms.Band5Start=0;
    tTempPtrPortProfile->PortProvParms.Band5Stop=0;

    tTempPtrPortProfile->PortProvParms.RFIBand1 = 0;
    tTempPtrPortProfile->PortProvParms.RFIBand2 = 0;
    tTempPtrPortProfile->PortProvParms.RFIBand3 = 0;
    tTempPtrPortProfile->PortProvParms.RFIBand4 = 0;
    tTempPtrPortProfile->PortProvParms.RFIBand5 = 0;
	tTempPtrPortProfile->PortProvParms.UsMinProtection=0;
	tTempPtrPortProfile->PortProvParms.DsMinProtection=0;
#ifdef CPE_40
#ifdef INI_SUPPORT
	tTempPtrPortProfile->PortProvParms.framingmode=0x80;
#else
	tTempPtrPortProfile->PortProvParms.framingmode=0;
#endif
#endif
	
	tTempPtrPortProfile->OptionParms.PortOption = 1;
	tTempPtrPortProfile->OptionParms.Reserved1 = 0;
	tTempPtrPortProfile->OptionParms.Reserved2 = 0;
	tTempPtrPortProfile->OptionParms.Reserved3 = 0;
	
	/* Port Instantiate paramaters */

	/* Port Start Reset parameters */
	tTempPtrPortProfile->PortStartResetParms.PortStartParm = 0; /* StartMode - Port Initiate, 
	 													   RateAdaptationMode - Fixed */	

	/* Port Stop parameters */
	tTempPtrPortProfile->PortStopParms.PortStopParm = 1; /* graceful stop */

	tTempPtrPortProfile->BandMod.bandModifier = 0x33;		//optional band off
	/* Port Destroy parameters */
    tTempPtrPortProfile->IFE_BRD_CFG.pwrMode = 0;
    tTempPtrPortProfile->IFE_BRD_CFG.rxPathFilterMode = 0;
    tTempPtrPortProfile->IFE_BRD_CFG.txPathFilterMode = 0;
	return; 
}

void setCoDefaultPortProfile (int profilenum)
{
	ipos_port_profile *tTempPtrPortProfile;

	tTempPtrPortProfile = &sPortProfiles[profilenum];

	tTempPtrPortProfile->PortProfileNum=profilenum;

	/* Port Provision parameters */ 
	tTempPtrPortProfile->PortProvParms.InterleavedChannel = 1; /* 0 - 63 */
	tTempPtrPortProfile->PortProvParms.FastChannel = 0; /* 0 - 63 */		
	tTempPtrPortProfile->PortProvParms.LineType = 0x81; /* automatic */	
	tTempPtrPortProfile->PortProvParms.DslMode = 5; /* Both fast and interleaved/slow channel exists */
	tTempPtrPortProfile->PortProvParms.RateAdaptationMode = 1; /* Startup */	
	tTempPtrPortProfile->PortProvParms.InterleavedPercentage = 0;
	tTempPtrPortProfile->PortProvParms.UpstreamMaxRateFast = 0; /* x64 kbps */ 
	tTempPtrPortProfile->PortProvParms.UpstreamMinRateFast = 0; /* x64 kbps */
	tTempPtrPortProfile->PortProvParms.UpstreamMaxRateSlow = 3125; /* x64 kbps */
	tTempPtrPortProfile->PortProvParms.UpstreamMinRateSlow = 1;  /* x64 kbps */	
	tTempPtrPortProfile->PortProvParms.UpstreamMaxInterDelay = 4; /* milli seconds 0.5ms */
	tTempPtrPortProfile->PortProvParms.DownstreamMaxRateFast = 0; /* x64 kbps */
	tTempPtrPortProfile->PortProvParms.DownstreamMinRateFast = 0; /* x64 kbps */
	tTempPtrPortProfile->PortProvParms.DownstreamMaxRateSlow = 3125; /* x64 kbps */
	tTempPtrPortProfile->PortProvParms.DownstreamMinRateSlow = 1; /* x64 kbps */
	tTempPtrPortProfile->PortProvParms.DownstreamMaxInterDelay = 4; /* milli seconds 0.5 ms */
	tTempPtrPortProfile->PortProvParms.NumParityFast = 4; /* no.of parity bytes */
	tTempPtrPortProfile->PortProvParms.NumParitySlow = 4; /* no.of parity bytes */
	tTempPtrPortProfile->PortProvParms.UsTargetNoiseMargin = 12; /* 0 - 31.0 db, steps of 0.5 db */
	tTempPtrPortProfile->PortProvParms.DsTargetNoiseMargin = 12; /* 0 - 31 db, steps of 0.5 db */
	tTempPtrPortProfile->PortProvParms.MinNoiseMargin = 10; /* 0 - 31 db, steps of 0.5 db */
	tTempPtrPortProfile->PortProvParms.BandPlan=BP3_998_4;
    tTempPtrPortProfile->PortProvParms.NumRFIBand=0;
	    /* Set these if NumRFIBand>0*/
    tTempPtrPortProfile->PortProvParms.Band1Start=0;
    tTempPtrPortProfile->PortProvParms.Band1Stop=0;
    tTempPtrPortProfile->PortProvParms.Band2Start=0;
    tTempPtrPortProfile->PortProvParms.Band2Stop=0;
    tTempPtrPortProfile->PortProvParms.Band3Start=0;
    tTempPtrPortProfile->PortProvParms.Band3Stop=0;
    tTempPtrPortProfile->PortProvParms.Band4Start=0;
    tTempPtrPortProfile->PortProvParms.Band4Stop=0;
    tTempPtrPortProfile->PortProvParms.Band5Start=0;
    tTempPtrPortProfile->PortProvParms.Band5Stop=0;

    tTempPtrPortProfile->PortProvParms.RFIBand1 = 0;
    tTempPtrPortProfile->PortProvParms.RFIBand2 = 0;
    tTempPtrPortProfile->PortProvParms.RFIBand3 = 0;
    tTempPtrPortProfile->PortProvParms.RFIBand4 = 0;
    tTempPtrPortProfile->PortProvParms.RFIBand5 = 0;
	tTempPtrPortProfile->PortProvParms.DsMinProtection=0;
	tTempPtrPortProfile->PortProvParms.UsMinProtection=0;
#ifdef CPE_40
#ifdef INI_SUPPORT
	tTempPtrPortProfile->PortProvParms.framingmode=0x80;
#else
	tTempPtrPortProfile->PortProvParms.framingmode=0;
#endif
#endif
    tTempPtrPortProfile->OptionParms.PortOption = 1;
	tTempPtrPortProfile->OptionParms.Reserved1 = 0;
	tTempPtrPortProfile->OptionParms.Reserved2 = 0;
	tTempPtrPortProfile->OptionParms.Reserved3 = 0;
	
	/* Port Instantiate paramaters */

	/* Port Start Reset parameters */
	tTempPtrPortProfile->PortStartResetParms.PortStartParm = 0; /* StartMode - Port Initiate, 
	 													   RateAdaptationMode - Fixed */	

	/* Port Stop parameters */
	tTempPtrPortProfile->PortStopParms.PortStopParm = 1; /* graceful stop */

	tTempPtrPortProfile->BandMod.bandModifier = 0x33;		//optional band off
	
    tTempPtrPortProfile->IFE_BRD_CFG.pwrMode = 0;
    tTempPtrPortProfile->IFE_BRD_CFG.rxPathFilterMode = 0;
    tTempPtrPortProfile->IFE_BRD_CFG.txPathFilterMode = 0;
    /* Port Destroy parameters */


	return; 
}

/********************************************************************************\
	Name 	   : setUserDefinedPortProfile							 
	Purpose    : If the user wants to have a specific port profile with specific
					port parameter values, different from the default port profile,
					he can change in this function.Then the user can assign this 
					port profile to the corresponding port.	
	Parameters : 
	no		Name		Type			Description
	--		----		----			-----------
	1. bProfileNum		U8		Port Profile Number

	Return	   : 
	Type				Description
	----				-----------
	eProfileMgmtRv		if success, PROFILE_MGMT_REQ_SUCCESS
						if error, WRONG_PROFILE_NUMBER, 
\********************************************************************************/
eProfileMgmtRv setUserDefinedPortProfile (U8 bProfileNum)
{
	ipos_port_profile *tTempPtrPortProfile;

	if (bProfileNum >= MAX_PORT_PROFILES)
	{
		printf ("\nWrong Profile number! Unable to process the request!");
		return WRONG_PROFILE_NUMBER;
	}

	tTempPtrPortProfile = &sPortProfiles[bProfileNum/*-1!*/];

	tTempPtrPortProfile->PortProfileNum=bProfileNum;

	/* Port Provision parameters */
	tTempPtrPortProfile->PortProvParms.InterleavedChannel = 0; /* 0 - 63 */
	tTempPtrPortProfile->PortProvParms.FastChannel = 1; /* 0 - 63 */		
	tTempPtrPortProfile->PortProvParms.LineType = 0x81; /* automatic */	
	tTempPtrPortProfile->PortProvParms.DslMode = 5; /* Both fast and interleaved/slow channel exists */
	tTempPtrPortProfile->PortProvParms.RateAdaptationMode = 1; /* Startup */	
	tTempPtrPortProfile->PortProvParms.InterleavedPercentage = 0;
	tTempPtrPortProfile->PortProvParms.UpstreamMaxRateFast = 0; /* x64 kbps */ 
	tTempPtrPortProfile->PortProvParms.UpstreamMinRateFast = 0; /* x64 kbps */
	tTempPtrPortProfile->PortProvParms.UpstreamMaxRateSlow = 3125; /* x64 kbps */
	tTempPtrPortProfile->PortProvParms.UpstreamMinRateSlow = 1;  /* x64 kbps */	
	tTempPtrPortProfile->PortProvParms.UpstreamMaxInterDelay = 4; /* milli seconds 0.5ms */
	tTempPtrPortProfile->PortProvParms.DownstreamMaxRateFast = 0; /* x64 kbps */
	tTempPtrPortProfile->PortProvParms.DownstreamMinRateFast = 0; /* x64 kbps */
	tTempPtrPortProfile->PortProvParms.DownstreamMaxRateSlow = 3125; /* x64 kbps */
	tTempPtrPortProfile->PortProvParms.DownstreamMinRateSlow = 1; /* x64 kbps */
	tTempPtrPortProfile->PortProvParms.DownstreamMaxInterDelay = 4; /* milli seconds 0.5ms */
	tTempPtrPortProfile->PortProvParms.NumParityFast = 4; /* no.of parity bytes */
	tTempPtrPortProfile->PortProvParms.NumParitySlow = 4; /* no.of parity bytes */
	tTempPtrPortProfile->PortProvParms.UsTargetNoiseMargin = 12; /* 0 - 31.0 db, steps of 0.5 db */
	tTempPtrPortProfile->PortProvParms.DsTargetNoiseMargin = 12; /* 0 - 31 db, steps of 0.5 db */
	tTempPtrPortProfile->PortProvParms.MinNoiseMargin = 10; /* 0 - 31 db, steps of 0.5 db */
	tTempPtrPortProfile->PortProvParms.BandPlan=BP2_998_3;
    tTempPtrPortProfile->PortProvParms.NumRFIBand=0;
    /* Set these if NumRFIBand>0
    tTempPtrPortProfile->PortProvParms.Band1Start=
    tTempPtrPortProfile->PortProvParms.Band1Stop...*/

    tTempPtrPortProfile->PortProvParms.Band1Start=0;
    tTempPtrPortProfile->PortProvParms.Band1Stop=0;
    tTempPtrPortProfile->PortProvParms.Band2Start=0;
    tTempPtrPortProfile->PortProvParms.Band2Stop=0;
    tTempPtrPortProfile->PortProvParms.Band3Start=0;
    tTempPtrPortProfile->PortProvParms.Band3Stop=0;
    tTempPtrPortProfile->PortProvParms.Band4Start=0;
    tTempPtrPortProfile->PortProvParms.Band4Stop=0;
    tTempPtrPortProfile->PortProvParms.Band5Start=0;
    tTempPtrPortProfile->PortProvParms.Band5Stop=0;

      tTempPtrPortProfile->PortProvParms.RFIBand1 = 0;
      tTempPtrPortProfile->PortProvParms.RFIBand2 = 0;
      tTempPtrPortProfile->PortProvParms.RFIBand3 = 0;
      tTempPtrPortProfile->PortProvParms.RFIBand4 = 0;
      tTempPtrPortProfile->PortProvParms.RFIBand5 = 0;
      tTempPtrPortProfile->PortProvParms.DsMinProtection=0;
	  tTempPtrPortProfile->PortProvParms.UsMinProtection=0;
#ifdef CPE_40
#ifdef INI_SUPPORT
      tTempPtrPortProfile->PortProvParms.framingmode=0x80;
#else
      tTempPtrPortProfile->PortProvParms.framingmode=0;
#endif
#endif
      tTempPtrPortProfile->OptionParms.PortOption = 1;
	  tTempPtrPortProfile->OptionParms.Reserved1 = 0;
	  tTempPtrPortProfile->OptionParms.Reserved2 = 0;
	  tTempPtrPortProfile->OptionParms.Reserved3 = 0;

	/* Port Instantiate paramaters */

	/* Port Start Reset parameters */
	tTempPtrPortProfile->PortStartResetParms.PortStartParm = 0; /* StartMode - Port Initiate, 
															   RateAdaptationMode - Fixed */	

	/* Port Stop parameters */
	tTempPtrPortProfile->PortStopParms.PortStopParm = 1; /* graceful stop */

	tTempPtrPortProfile->BandMod.bandModifier = 0x33;		// optional band off
	/* Port Destroy parameters */

    tTempPtrPortProfile->IFE_BRD_CFG.pwrMode = 0;
    tTempPtrPortProfile->IFE_BRD_CFG.rxPathFilterMode = 0;
    tTempPtrPortProfile->IFE_BRD_CFG.txPathFilterMode = 0;
	return (PROFILE_MGMT_REQ_SUCCESS);
}
 
/********************************************************************************\
	Name 	   : getPortProfileDisplay							 
	Purpose    : If the user wants to see a specific port profile and all the
					port parameter values, he can call this function by passing the
					port profile number which he is interested in viewing.
	Parameters : 
	no		Name		Type			Description
	--		----		----			-----------
	1. bProfileNum		U8		Port Profile Number

	Return	   : void
	
\********************************************************************************/
void getPortProfileDisplay (U8 bProfileNum)
{
	ipos_port_profile *pPortProfile;

	char  bin_str[9];
	if (bProfileNum >= MAX_PORT_PROFILES)
	{
		printf ("\nWrong Profile number! Unable to process the request!");
		return;
	}

	pPortProfile = &sPortProfiles[bProfileNum];

	printf ("\n--------------------------------------------------------------------------");
	printf ("\ngetPortProfile %d", bProfileNum);
	printf ("\n--------------------------------------------------------------------------");
	/* Port Provision parameters */
	printf ("\n\nPORT_PROVISION");
	printf ("\nInterleavedChannel :0x%x", pPortProfile->PortProvParms.InterleavedChannel);
	printf ("\nFastChannel :0x%x", pPortProfile->PortProvParms.FastChannel);
	printf ("\nLineType :0x%x", pPortProfile->PortProvParms.LineType);
	printf ("\nDslMode :0x%x", pPortProfile->PortProvParms.DslMode);
	printf ("\nRateAdaptationMode :0x%x", pPortProfile->PortProvParms.RateAdaptationMode);
	printf ("\nInterleavedPercentage :0x%x", pPortProfile->PortProvParms.InterleavedPercentage);
	printf ("\nUpstreamMaxRateFast :0x%lx", pPortProfile->PortProvParms.UpstreamMaxRateFast);
	printf ("\nUpstreamMinRateFast :0x%lx", pPortProfile->PortProvParms.UpstreamMinRateFast);
	printf ("\nUpstreamMaxRateSlow :0x%lx", pPortProfile->PortProvParms.UpstreamMaxRateSlow);
	printf ("\nUpstreamMinRateSlow :0x%lx", pPortProfile->PortProvParms.UpstreamMinRateSlow);
	printf ("\nUpstreamMaxInterDelay :0x%x", pPortProfile->PortProvParms.UpstreamMaxInterDelay);
	printf ("\nDownstreamMaxRateFast :0x%lx", pPortProfile->PortProvParms.DownstreamMaxRateFast);
	printf ("\nDownstreamMinRateFast :0x%lx", pPortProfile->PortProvParms.DownstreamMinRateFast);
	printf ("\nDownstreamMaxRateSlow :0x%lx", pPortProfile->PortProvParms.DownstreamMaxRateSlow);
	printf ("\nDownstreamMinRateSlow :0x%lx",pPortProfile->PortProvParms.DownstreamMinRateSlow);
	printf ("\nDownstreamMaxInterDelay :0x%x", pPortProfile->PortProvParms.DownstreamMaxInterDelay);
	printf ("\nNumParityFast :0x%x",pPortProfile->PortProvParms.NumParityFast);
	printf ("\nNumParitySlow :0x%x", pPortProfile->PortProvParms.NumParitySlow);
	printf ("\nUsTargetNoiseMargin :0x%x", pPortProfile->PortProvParms.UsTargetNoiseMargin);
	printf ("\nDsTargetNoiseMargin :0x%x", pPortProfile->PortProvParms.DsTargetNoiseMargin);
	printf ("\nMinNoiseMargin :0x%x", pPortProfile->PortProvParms.MinNoiseMargin);
	//printf ("\nBand Plan :0x%x", pPortProfile->PortProvParms.BandPlan);
    printf ("\nNumRFIBand :0x%x", pPortProfile->PortProvParms.NumRFIBand);

 	displayRFIBandSetting (pPortProfile->PortProvParms.RFIBand1, bin_str);
    printf( "\n\nRFIBand[8 7 6 ... 1]: %s",bin_str);
	displayRFIBandSetting (pPortProfile->PortProvParms.RFIBand2, bin_str);
    printf( "\nRFIBand[16 15 ... 9]: %s",bin_str);
	displayRFIBandSetting (pPortProfile->PortProvParms.RFIBand3, bin_str);
    printf( "\nRFIBand[24 23 .. 17]: %s",bin_str);
	displayRFIBandSetting (pPortProfile->PortProvParms.RFIBand4, bin_str);
    printf( "\nRFIBand[32 31 .. 25]: %s",bin_str);
	displayRFIBandSetting (pPortProfile->PortProvParms.RFIBand5, bin_str);
    printf( "\nRFIBand[40 39 .. 33]: %s",bin_str);

	/* Port Instantiate paramaters */

	/* Port Start Reset parameters */
	printf ("\n\nPortStartParm :0x%x", pPortProfile->PortStartResetParms.PortStartParm);

   	printf ("\n\nbandModifier	:0x%x", pPortProfile->BandMod.bandModifier);
                                                      
   	printf ("\n\nPortOption 	:0x%x", pPortProfile->OptionParms.PortOption);
    printf ("\n\nDsMinProtection    :0x%x", pPortProfile->PortProvParms.DsMinProtection);
    printf ("\n\nUsMinProtection    :0x%x", pPortProfile->PortProvParms.UsMinProtection);

   	printf ("\nReserved1 :0x%x", pPortProfile->OptionParms.Reserved1);
   	printf ("\nReserved2 :0x%x", pPortProfile->OptionParms.Reserved2);
   	printf ("\nReserved3 :0x%x", pPortProfile->OptionParms.Reserved3);

    printf("\n ife board power mode: %d", oampGetIFE2PwrMode);
    printf("\n ife per port power mode: %d", pPortProfile->IFE_BRD_CFG.pwrMode);
    printf("\n ife per port rxHPF mode: %d", pPortProfile->IFE_BRD_CFG.rxPathFilterMode);
    printf("\n ife per port txFilter mode: %d", pPortProfile->IFE_BRD_CFG.txPathFilterMode);

	/* Port Destroy parameters */
#ifdef CPE_40
    printf ("\n\nNetwork Framing    :0x%x", pPortProfile->PortProvParms.framingmode);
#endif
	printf ("\n--------------------------------------------------------------------------\n");
	return;
}

int memcpyProfile (int SrcProfileNum, int DestProfileNum)
{

if ((SrcProfileNum>=MAX_PORT_PROFILES) || (DestProfileNum>=MAX_PORT_PROFILES))
	{
		printf ("\nWrong Profile number! Unable to process the request!");
		return ERROR;
	}

	memcpy((U8 *)&sPortProfiles[DestProfileNum], (U8 *)&sPortProfiles[SrcProfileNum], sizeof (ipos_port_profile));
	sPortProfiles[DestProfileNum].PortProfileNum = DestProfileNum+1;
	return TRUE;

}

/********************************************************************************\
	Name 	   : readProfileFromFlash							 
	Purpose    : Read port profile from flash memory.

	Parameters : 
	no		Name		Type			Description
	--		----		----			-----------
	1. bProfileNum		U8		Port Profile Number

	Return	   : void
	
\********************************************************************************/
void readProfileFromFlash (U8 ProfileNum)
{
  char *pProfileLoc = (char *)PORT_PROFILE_BASE;

  if (ProfileNum < MAX_PORT_PROFILES)
  {
	if (ProfileNum==0)
		// Profile Number 0 is the last one in flash memory for backward compatibility
		pProfileLoc += ((MAX_PORT_PROFILES-1) * pprofileSize);
	else
    	pProfileLoc += ((ProfileNum - 1) * pprofileSize);
    memcpy(&sPortProfiles[ProfileNum], pProfileLoc, pprofileSize);
  }
  else
    printf ("\nERROR: Unsupported port profile number %i,",ProfileNum);
} /* readProfileFromFlash */


static void getProfileFromFlash (U8 ProfileNum)
{

U32 size=0;
U32 TotalSize=0;
char *pProfileLoc = (char*)PORT_PROFILE_1;
U8 TmpDataBuff[100];

if (ProfileNum==1) pProfileLoc=(char*)PORT_PROFILE_1;
else if (ProfileNum==2) pProfileLoc=(char*)PORT_PROFILE_2;
else if (ProfileNum==0) pProfileLoc=(char*)PORT_PROFILE_0;
else {printf ("\nERROR: Unsupported port profile number %i,",ProfileNum); return;}


memcpy(&TmpDataBuff[0],pProfileLoc,TOTAL_PORTPARMS);

/* These values stay in host processor only, so no need to change endian type */
	size=sizeof(sPortProfiles[ProfileNum].PortProvParms.InterleavedChannel);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.InterleavedChannel),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.FastChannel);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.FastChannel),&TmpDataBuff[TotalSize],size);  
	TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.LineType);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.LineType),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.DslMode);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.DslMode),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;
  
        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.RateAdaptationMode);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.RateAdaptationMode),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.InterleavedPercentage);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.InterleavedPercentage),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.UpstreamMaxRateFast);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.UpstreamMaxRateFast),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.UpstreamMinRateFast);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.UpstreamMinRateFast),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.UpstreamMaxRateSlow);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.UpstreamMaxRateSlow),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.UpstreamMinRateSlow);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.UpstreamMinRateSlow),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.UpstreamMaxInterDelay);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.UpstreamMaxInterDelay),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.DownstreamMaxRateFast);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.DownstreamMaxRateFast),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.DownstreamMinRateFast);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.DownstreamMinRateFast),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.DownstreamMaxRateSlow);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.DownstreamMaxRateSlow),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.DownstreamMinRateSlow);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.DownstreamMinRateSlow),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.DownstreamMaxInterDelay);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.DownstreamMaxInterDelay),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.NumParityFast);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.NumParityFast),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;
        
        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.NumParitySlow);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.NumParitySlow),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.UsTargetNoiseMargin);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.UsTargetNoiseMargin),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.DsTargetNoiseMargin);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.DsTargetNoiseMargin),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.MinNoiseMargin);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.MinNoiseMargin),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.BandPlan);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.BandPlan),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.NumRFIBand);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.NumRFIBand),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.Band1Start);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.Band1Start),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.Band1Stop);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.Band1Stop),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;
  
        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.Band2Start);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.Band2Start),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.Band2Stop);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.Band2Stop),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.Band3Start);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.Band3Start),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;


        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.Band3Stop);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.Band3Stop),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.Band4Start);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.Band4Start),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.Band4Stop);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.Band4Stop),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.Band5Start);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.Band5Start),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.Band5Stop);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.Band5Stop),&TmpDataBuff[TotalSize],size);
        TotalSize+=size;

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.RFIBand1);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.RFIBand1), &TmpDataBuff[TotalSize], size);
        TotalSize+=size;   
        
		size=sizeof(sPortProfiles[ProfileNum].PortProvParms.RFIBand2);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.RFIBand2), &TmpDataBuff[TotalSize], size);
        TotalSize+=size;   
        
        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.RFIBand3);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.RFIBand3), &TmpDataBuff[TotalSize], size);
        TotalSize+=size;   

        size=sizeof(sPortProfiles[ProfileNum].PortProvParms.RFIBand4);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.RFIBand4), &TmpDataBuff[TotalSize], size);
        TotalSize+=size;   
        
		size=sizeof(sPortProfiles[ProfileNum].PortProvParms.RFIBand5);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.RFIBand5), &TmpDataBuff[TotalSize], size);
        TotalSize+=size;   

		size=sizeof(sPortProfiles[ProfileNum].PortProvParms.UsMinProtection);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.UsMinProtection), &TmpDataBuff[TotalSize], size);
        TotalSize+=size;  

		size=sizeof(sPortProfiles[ProfileNum].PortProvParms.DsMinProtection);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.DsMinProtection), &TmpDataBuff[TotalSize], size);
        TotalSize+=size;  

#ifdef CPE_40
		size=sizeof(sPortProfiles[ProfileNum].PortProvParms.framingmode);
        memcpy(&(sPortProfiles[ProfileNum].PortProvParms.framingmode), &TmpDataBuff[TotalSize], size);
        TotalSize+=size;  
#endif
		size=sizeof(sPortProfiles[ProfileNum].OptionParms.PortOption);
        memcpy(&(sPortProfiles[ProfileNum].OptionParms.PortOption), &TmpDataBuff[TotalSize], size);
        TotalSize+=size;   

		size=sizeof(sPortProfiles[ProfileNum].OptionParms.Reserved1);
        memcpy(&(sPortProfiles[ProfileNum].OptionParms.Reserved1), &TmpDataBuff[TotalSize], size);
        TotalSize+=size;  

		size=sizeof(sPortProfiles[ProfileNum].OptionParms.Reserved2);
        memcpy(&(sPortProfiles[ProfileNum].OptionParms.Reserved2), &TmpDataBuff[TotalSize], size);
        TotalSize+=size;  

		size=sizeof(sPortProfiles[ProfileNum].OptionParms.Reserved3);
        memcpy(&(sPortProfiles[ProfileNum].OptionParms.Reserved3), &TmpDataBuff[TotalSize], size);
        TotalSize+=size;  

} /* getProfileFromFlash */

void savePreviousProfiles (int version)
{
  // int i=0;
  //char *pProfileLoc = (char *)PORT_PROFILE_BASE;


  if (version <= 2)
  {
    getProfileFromFlash(1);
    getProfileFromFlash(2);
    getProfileFromFlash(0);
  }
  else 
  {

    readProfileFromFlash (1);
    readProfileFromFlash (2);
    readProfileFromFlash (0);

  }

  if (version>=12)
  {	
  getProfileMapping();
  }
  else
  {
#ifdef VTU_O
    setCoDefaultPortProfile(0);
#else
	setCpeDefaultPortProfile(0);
#endif
  }

}

/********************************************************************************\
	Name 	   : writeProfileToFlash							 
	Purpose    : Write updated port profile to flash memory.

	Parameters : 
	no		Name		Type			Description
	--		----		----			-----------
	1. bProfileNum		U8		Port Profile Number

	Return	   : void
	
\********************************************************************************/
void writeProfileToFlash (void)
{
  char * pProfileLoc=(char*)PORT_PROFILE_BASE;
	
  FlashWrite ((unsigned char volatile*)pProfileLoc,
              (unsigned char*)&sPortProfiles[1], sizeof(ipos_port_profile));
	pProfileLoc += sizeof(ipos_port_profile);
	FlashWrite ((unsigned char volatile*)pProfileLoc,
              (unsigned char*)&sPortProfiles[2], sizeof(ipos_port_profile));
	pProfileLoc += sizeof(ipos_port_profile);
	FlashWrite ((unsigned char volatile*)pProfileLoc,
              (unsigned char*)&sPortProfiles[0], sizeof(ipos_port_profile));
	pProfileLoc += sizeof(ipos_port_profile);


	// Save Profile Mapping in flash, along with check string
	FlashWrite ((unsigned char volatile*)pProfileLoc,PROFILE_CHKSTR, sizeof (PROFILE_CHKSTR));
	pProfileLoc += 0x10;
	FlashWrite ((unsigned char volatile*)pProfileLoc,
              (unsigned char*)&ProfileMapping[1], IPOS_MAX_PORTS*sizeof (int));
	


} /* writeProfileToFlash */


void setPortOption (int profileNum)
{
  int i;
  int iChoice, uidone;
  char tempStr[20];
  char carrSetNames[MAX_AVAILABLE_CARR_SETS][4] = {"I43", "V43", "A43", "B43"};
  U8 carrSet, bitmask, dmtNoiseOption;

  /* 
   * Bit Mapping for Port Option byte
   *   Bit 0     :  I43 G.hs Carrier set Enable (1 = 0n; 0 = off) 
   *   Bit 1     :  V43 G.hs Carrier set Enable (1 = 0n; 0 = off) 
   *   Bit 2     :  A43 G.hs Carrier set Enable (1 = 0n; 0 = off) 
   *   Bit 3     :  B43 G.hs Carrier set Enable (1 = 0n; 0 = off) 
   */

  carrSet = sPortProfiles[profileNum].OptionParms.PortOption & 0xf;
  dmtNoiseOption = sPortProfiles[profileNum].OptionParms.Reserved3;
  uidone = 0;

  do {

    printf("\n\nG.hs Carrier Set Configuration");
    printf("\n==============================");
    for (i = 0; i < MAX_AVAILABLE_CARR_SETS; i++) {
      printf("\n %2d)  %s Carrier Set:  %s", i+1, carrSetNames[i],
              (carrSet & (0x1 << i)) ? "ON" : "OFF");
    }
    printf ("\n\n Select 1-%d to toggle carrier sets, 0 to disable G.hs", MAX_AVAILABLE_CARR_SETS);
    printf ("\n or Press Enter to Exit: >> ");
    //gets(tempStr);
    scanf("%s",tempStr);
    fflush(stdout);
    printf("Here %s\n",tempStr);
    if (strcmp("exit",tempStr) == 0)
    {
      /* Exit condition */
      uidone = 1;

      if (carrSet == 0)
		{
        printf ("\nG.hs Disabled");
			printf ("\n Enter DMT Noise Option (1- Enable  0- Disable) [%d]: ", dmtNoiseOption & 0x1);
		//	gets(tempStr);
                        scanf("%s",tempStr);
                        fflush(stdout);
			if ( strlen(tempStr) > 0 )
			{
			 U8 k;
				k = (U8)atoi(tempStr);
				if ( k == 0 )
				{
					dmtNoiseOption &= ~0x1;
				}
				else if ( k == 1 )
				{
					dmtNoiseOption |= 0x1;
				}
				else
				{
					/* no action, revert back to original value */
				}
			}
		}
		else
		{
			/* disable dmt noise option */
			dmtNoiseOption &= ~0x1;
		}

    } else {

      iChoice = atoi(tempStr);

      if (iChoice == 0)
      {
        /* Disable G.hs. Turn off all tones. */
        carrSet = 0;

      } else if (iChoice > 0 && iChoice <= MAX_AVAILABLE_CARR_SETS)
      {
        /* Toggle the corresponding bit */
        bitmask = 0x1 << (iChoice-1);
        carrSet = (carrSet & bitmask) ? carrSet & ~bitmask: carrSet | bitmask;

      } else
        printf("\nInvalid Choice Entered");

    }

  } while (uidone == 0);

  // Store the carrSet options in 0-4 bits of PortOption element of PortProfile
  sPortProfiles[profileNum].OptionParms.PortOption = carrSet;
  sPortProfiles[profileNum].OptionParms.Reserved3 = dmtNoiseOption;

}


int configureRfiBands (int profileNum)
{
 ipos_port_profile *PPP = &sPortProfiles[profileNum];
 int iStatus, iChoice, i, iMaskIdx, iLoop = 1/*, j = 0, k = 0*/;
 char buf[20];
 U8 ucRfi;
#if 0
 /* This mapping had to be added, due the addition of KT Ham Band's. 
  * Reason : KT Ham Band's were lying in the same frequencies, as the standard table.
  * I did not want to disturb the order of printing of the RFI Band's. So, I have 
  * introduced this table, which maps the bands to their original numbers, though 
  * the printing has changed. The KT bands are sent to the BME as 14, 15 and 16. 
  */
 int rfi_mapping [16] = {
                          16, 13, 0, 1, 2, 14, 3, 4, 5, 6, 15, 7, 8, 9, 10, 11, 12 
                        }; 
#endif
   iStatus = 0;
	while ( iLoop )
	{
		printf("\n RFI-BAND CONFIGURATION");
		printf("\n =======================================================");
		for ( i=0 ; i<MAX_AVAILABLE_RFI_BANDS; i++ )
		{
			if ( i < 8 )
			{
				ucRfi = PPP->PortProvParms.RFIBand1;
				iMaskIdx = i;
			}
			else if ( i < 16 )
			{
				ucRfi = PPP->PortProvParms.RFIBand2;
				iMaskIdx = i - 8;
			}
			else if ( i < 24 )
			{
				ucRfi = PPP->PortProvParms.RFIBand3;
				iMaskIdx = i - 16;
			}
			else if ( i < 32 )
			{
				ucRfi = PPP->PortProvParms.RFIBand4;
				iMaskIdx = i - 24;
			}
			else
			{
				ucRfi = PPP->PortProvParms.RFIBand5;
				iMaskIdx = i - 32;
			}

			printf("\n %2d) RFI-BAND%02d:  %s  %s", (i+1), (i+1), 
                   (ucRfi & GetRfiMask[iMaskIdx]) ? "ON ":"OFF", availableRfiBands[i]);
		}
		printf("\n 99) EXIT");
		printf ("\n\n Select 1-%d to toggle RFI-BANDS or 99 to Exit: \n >> ", MAX_AVAILABLE_RFI_BANDS);
			
		// gets(buf);
        scanf("%s",buf);
        fflush(stdout);
        iChoice = atoi(buf);
		
		switch ( iChoice )
		{
			case 1:	
			case 2:	
			case 3:	
			case 4:	
			case 5:	
			case 6:	
			case 7:	
			case 8:
				PPP->PortProvParms.RFIBand1 ^= GetRfiMask [iChoice-1];
				iStatus = 1;
				break;
			case 9:	
			case 10:	
			case 11:	
			case 12:	
			case 13:	
            case 14:
            case 15:
            case 16:
                PPP->PortProvParms.RFIBand2 ^= GetRfiMask [iChoice-9];
				iStatus = 1;
				break;
            case 17:
      case 18:
      case 19:
      case 20:
      case 21:
                PPP->PortProvParms.RFIBand3 ^= GetRfiMask [iChoice-17];
				iStatus = 1;
				break;
			case 99:	
				iLoop = 0; 	
				break;
			default: 			
				break;
		}
	}

	return (iStatus);
}



int RemapMenuCmd(int ParmType)
{

switch (ParmType)
	{
	case 1:
		  return INTERLEAVED_PERCENTAGE; break;
	case 2:
		  return UPSTREAM_MAX_RATE_FAST; break;
	case 3:
		  return UPSTREAM_MIN_RATE_FAST; break;
	case 4:
		  return UPSTREAM_MAX_RATE_SLOW; break;
	case 5:
		  return UPSTREAM_MIN_RATE_SLOW; break;
	case 6:
		  return UPSTREAM_MAX_INTER_DELAY; break;
	case 7:
		  return DOWNSTREAM_MAX_RATE_FAST; break;
	case 8:
		  return DOWNSTREAM_MIN_RATE_FAST; break;
	case 9:
		  return DOWNSTREAM_MAX_RATE_SLOW; break;
	case 10:
		  return DOWNSTREAM_MIN_RATE_SLOW; break;
	case 11:
		  return DOWNSTREAM_MAX_INTER_DELAY; break;
	case 20:
		  return DS_TARGET_NOISE_MARGIN; break;
	case 22:
		  return MIN_NOISE_MARGIN; break;
	case 14:
		return RFI_BANDS; break;
	case 15:
		return PORT_OPTION; break;
	case 16:
		return TONE_CONFIG; break;
	case 21:
		return US_TARGET_NOISE_MARGIN; break;
	case 24:
		return UPSTREAM_MIN_PROTECTION; break;
	case 25:
		return DOWNSTREAM_MIN_PROTECTION; break;

	default:
			break;
	}

  return (0);

} // RemapMenuCmd


/********************************************************************************\
	Name 	   : setPortProfile 
	Purpose    : Sets the Port Profile parameter selected by the user from the Menu.

	Parameters : 
	no		Name		Type			Description
	--		----		----			-----------
	1. ptrTlStr	 	   U8 *		Global string for storing the command.

	Return	   : UPDATE_IN_FLASH if some parameter is changed
                 DO_NOT_UPDATE if no parameter is changed.
	
\********************************************************************************/
int setPortProfile(U8 *ptrTlStr)
{
    char ProfNum[2];
    int ParmType,i;
#ifdef VTU_O
		int ParmType2;
    int ParmData;
    int displayMenu=1;
    int firstTime=0;
    char buf[20];
#else
    char sParmType[5];
    char sParmData[10];
#endif
		char input[]={0, 0};
	int srcProf=0;
	char confirm=0;
	ipos_port_profile *tTempPtrPortProfile;
    
	printf ("\n Enter port profile number: "); 
    //scanf ("%d", &ProfNum);
    // gets(ProfNum);
    scanf("%s",ProfNum);
    fflush(stdout);
    printf("Len %d\n",strlen(ProfNum));
    printf("Input String %s\n",ProfNum);
    // fgets(ProfNum,sizeof(ProfNum),stdin);
    if ((atoi(ProfNum) >= MAX_PORT_PROFILES) || (atoi(ProfNum) < 0))
	{
		printf ("\nWrong Profile number! Unable to process the request!");
		return ERROR; 
	}
	tTempPtrPortProfile = &sPortProfiles[atoi(ProfNum)];

#ifdef VTU_O    
    while (1)
    {   
        if(displayMenu)
        {
            printf("\n           PORT PROFILE MENU   ");
            printf("\n         =====================");
            printf("\n\n      1) Interleaved Percentage");
            printf("\n      2) Upstream Maximum Payload Data Rate (Fast Channel)"); 
            printf("\n      3) Upstream Minimum Payload Data Rate (Fast Channel)"); 
            printf("\n      4) Upstream Maximum Payload Data Rate (Slow Channel)"); 
            printf("\n      5) Upstream Minimum Payload Data Rate (Slow Channel)"); 
            printf("\n      6) Upstream Max. Interleave Delay");
            printf("\n      7) Downstream Maximum Payload Data Rate (Fast Channel)"); 
            printf("\n      8) Downstream Minimum Payload Data Rate (Fast Channel)"); 
            printf("\n      9) Downstream Maximum Payload Data Rate (Slow Channel)"); 
            printf("\n     10) Downstream Minimum Payload Data Rate (Slow Channel)"); 
            printf("\n     11) Downstream Max. Interleave Delay");	
	        printf("\n     14) Configure RFI Band");
	        printf("\n     15) Set Port Options");
	        printf("\n     16) Tone Disable Configuration");
            printf("\n     20) Downstream Target Noise Margin");
	        printf("\n     21) Upstream Target Noise Margin");
	        printf("\n     22) Minimum Noise Margin");	
            printf("\n     23) IFE 2 per port board Level cfg");               
            printf("\n     24) Set UpStream Minimum Protection");
            printf("\n     25) Set DownStream Minimum Protection");
	        printf("\n     97) Copy values from another profile");	
	        printf("\n     98) Restore profile to default values");
            printf("\n     99) Exit to the Main Menu");
            printf ("\n\n Select the Parameter type from the list: ");
            displayMenu = 0;
            //scanf ("%s",buf);
			gets(buf);
        }
        ParmType = atoi(buf);

	   if ( !firstTime && (ParmType == 99 ) )
        {
            ptrTlStr[0] = '\0';  //Null terminate the string
            return DO_NOT_UPDATE;
        }

        else if (ParmType == 99 )
        {
            ptrTlStr[0] = '\0';  //Null terminate the string
            return UPDATE_IN_FLASH;
        }
		else if (ParmType == 98)
		{
		    ptrTlStr[0] = '\0';  //Null terminate the string				
			setCoDefaultPortProfile(atoi(ProfNum));
            return UPDATE_IN_FLASH;
		}
		else if (ParmType == 97)
		{
            ptrTlStr[0] = '\0';  //Null terminate the string

			printf ("\nDestination profile is %i",atoi(ProfNum));
			printf ("\nEnter source profile: ");

			gets (input);
			sscanf (input,"%i",&srcProf);

			if ((srcProf<0) || (srcProf>MAX_PORT_PROFILES-1)) 
			{	
				printf ("\nInvalid profile number");
				return DO_NOT_UPDATE;
			}

			printf ("\nCopy profile %i to profile %i (y/n)? " ,
						srcProf,atoi(ProfNum));
			gets (input);
			sscanf (input,"%c", &confirm);

			if ((confirm=='y') || (confirm=='Y'))
			{
				printf ("\nCopying profile %i to profile %i",
						srcProf,atoi(ProfNum));
				if (memcpyProfile (srcProf,atoi(ProfNum))!=ERROR)
					return UPDATE_IN_FLASH;
				else return DO_NOT_UPDATE;
					
			}
			else
				return DO_NOT_UPDATE;

		} else if(ParmType == 23)
        {
            ife2_per_port_cfg(tTempPtrPortProfile);
            return UPDATE_IN_FLASH;
        }

        
		ParmType2=RemapMenuCmd(ParmType);
	if ( ParmType2 == RFI_BANDS )
		{
			ptrTlStr[0] = '\0';
			if ( configureRfiBands (atoi(ProfNum)) )
				return UPDATE_IN_FLASH;
			else
				return DO_NOT_UPDATE;
		}
	else if (ParmType2 == PORT_OPTION)
		{
		ptrTlStr[0] = '\0';
		setPortOption (atoi(ProfNum));
		return UPDATE_IN_FLASH;
		}
	else if (ParmType2 == TONE_CONFIG)
		{
		ptrTlStr[0] = '\0';
#ifdef VTU_O							
                        	configure_band(atoi(ProfNum), 0);
#else	
                        	configure_band(atoi(ProfNum), 1);
#endif
		return DO_NOT_UPDATE;
		}
	else
	{
        if(getParameters(atoi(ProfNum), ParmType2, &ParmData) == ERROR)
        {
                printf ("\nInvalid selection");
                ptrTlStr[0] = '\0';
                displayMenu = 1;
        }

        else
        {
            sprintf (ptrTlStr,"setpprof:0:%x:%x:%x;",atoi(ProfNum),ParmType2,ParmData);
            //printf ("ptrTlStr %s",ptrTlStr);
            if (strlen(ptrTlStr))
                ReceiveTLCommand (ptrTlStr);
            printf("\n\n Enter '1' to display this menu OR '99' to Exit to the Main Menu :");
            gets (buf);
            ParmType = atoi(buf);
            if (ParmType == 1) 
                displayMenu = 1;
            firstTime =1;
        }
	}

	}
#else  //VTU_R


            printf("\n         =====================");
            printf("\n           PORT PROFILE MENU   ");
            printf("\n         =====================");
	    	printf("\n\n      1) Min. Noise Margin");
            printf("\n\n      2) Interleaved Percentage");
	    	printf("\n\n      3) Upstream Max. Interleave Delay");
 	    	printf("\n\n      4) Downstream Max. Interleave Delay");
			printf("\n\n      5) Configure RFI Band");
			printf("\n\n      6) Set Port Options");	
			printf("\n\n      7) Tone Disable Configuration");	
            printf("\n\n      8) IFE II Configuration");
#ifdef CPE_40
            printf("\n\n      9) Network Configuration");
#endif
			printf("\n\n     97) Copy values from another profile");	
			printf("\n\n     98) Restore profile to default values");
            printf ("\n\n Select the Parameter type from the list ");
			printf ("\n Press Enter to exit menu without modifications: ");
			gets (sParmType);
//                        fgets(sParmType,sizeof(sParmType),stdin);
    fflush(stdin);
        scanf("%i",&i);
        printf("Fusiv Menu %d\n",i);
   fflush(stdin);
//	switch (atoi(sParmType))
	switch (i)
	{	
	case 1:
    	printf("\n Current Min. Noise Margin = %2.1f dB", ((float)tTempPtrPortProfile->PortProvParms.MinNoiseMargin)/2); 
    	printf("\n Enter the new value (0-62) x 0.5 dB :"); 
		gets (sParmData);
		if( (sParmData[0] != '\n') && (sParmData[0] != '\0') )
    		{
			//scanf("%d", &ParmData);
  	  		ParmType = MIN_NOISE_MARGIN;
    		sprintf (ptrTlStr,"setpprof:0:%x:%x:%x;",atoi(ProfNum),ParmType,atoi(sParmData));
    		//printf ("\nptrTlStr %s",ptrTlStr);	
    		ReceiveTLCommand (ptrTlStr);
			return UPDATE_IN_FLASH;
			}	
		else ptrTlStr[0] = '\0';
		break;

	case 2:
      printf("\n Current Data Path [%d%% Fastpath; %d%% Interleaved]", 
                           tTempPtrPortProfile->PortProvParms.InterleavedPercentage,
                           100 - tTempPtrPortProfile->PortProvParms.InterleavedPercentage);
      printf("\n Enter the new Fastpath Percentage: ");

    gets (sParmData);
		if( (sParmData[0] != '\n') && (sParmData[0] != '\0') )
    		{
			if (atoi(sParmData)>0) strcpy (sParmData,"100");
    		ParmType = INTERLEAVED_PERCENTAGE;
    		sprintf (ptrTlStr,"setpprof:0:%x:%x:%x;",atoi(ProfNum),ParmType,atoi(sParmData));
   		 	//printf ("\nptrTlStr %s",ptrTlStr);	
	    	ReceiveTLCommand (ptrTlStr);
       printf(" New Data Path [%d%% Fastpath; %d%% Interleaved]", 
                           tTempPtrPortProfile->PortProvParms.InterleavedPercentage,
                           100 - tTempPtrPortProfile->PortProvParms.InterleavedPercentage);

			return UPDATE_IN_FLASH;
			}
		else ptrTlStr[0] = '\0';
		break;

	case 3:
    	printf("\n Current Upstream Max. Interleave Delay= %2.1f ms", ((float)tTempPtrPortProfile->PortProvParms.UpstreamMaxInterDelay)/2); 
    	printf("\n Enter the new value (in units of 0.5 ms) :"); 
    	//scanf("%d", &ParmData);
              scanf("%s",sParmData);
    fflush(stdout);
	//	gets (sParmData);
		if( (sParmData[0] != '\n') && (sParmData[0] != '\0') )
    		{
  		  	ParmType = UPSTREAM_MAX_INTER_DELAY;
    		sprintf (ptrTlStr,"setpprof:0:%x:%x:%x;",atoi(ProfNum),ParmType,atoi(sParmData));
   			//printf ("\nptrTlStr %s",ptrTlStr);	
    		ReceiveTLCommand (ptrTlStr);
    		return UPDATE_IN_FLASH;
			}
		else ptrTlStr[0] = '\0';
		break;

	case 4:
    	printf("\n Current Downstream Max. Interleave Delay= %2.1f ms", ((float)tTempPtrPortProfile->PortProvParms.DownstreamMaxInterDelay)/2); 
    	printf("\n Enter the new value (in units of 0.5 ms) :"); 
    	//scanf("%d", &ParmData);
	//	gets (sParmData);
              scanf("%s",sParmData);
    fflush(stdout);
		if( (sParmData[0] != '\n') && (sParmData[0] != '\0') )
    		{    		
			ParmType = DOWNSTREAM_MAX_INTER_DELAY;
    		sprintf (ptrTlStr,"setpprof:0:%x:%x:%x;",atoi(ProfNum),ParmType,atoi(sParmData));
   			//printf ("\nptrTlStr %s",ptrTlStr);	
    		ReceiveTLCommand (ptrTlStr);
			return UPDATE_IN_FLASH;
			}
		else ptrTlStr[0] = '\0';
		break;
//jk-rfi
		case 5:
			ptrTlStr[0] = '\0';
			if ( configureRfiBands (atoi(ProfNum)) )
				return UPDATE_IN_FLASH;
			else
				return DO_NOT_UPDATE;
			break;

		case 6:
			ptrTlStr[0] = '\0';
			setPortOption (atoi(ProfNum));
			return UPDATE_IN_FLASH;

			break;
		case 7:
			ptrTlStr[0] = '\0';
#ifdef VTU_O							
                        configure_band(atoi(ProfNum), 0);
#else	
                        configure_band(atoi(ProfNum), 1);
#endif
			break;
        case 8:
            ife2_per_port_cfg(tTempPtrPortProfile);
            return UPDATE_IN_FLASH;
            break;

#ifdef CPE_40
        case 9:
            configure_ni(tTempPtrPortProfile);
            return UPDATE_IN_FLASH;
            break;
#endif
		case 97:
            ptrTlStr[0] = '\0';  //Null terminate the string

			printf ("\nDestination profile is %i",atoi(ProfNum));
			printf ("\nEnter source profile: ");
	//					gets (input);
              scanf("%s",input);
    fflush(stdout);
			sscanf (input,"%i",&srcProf);

			if ((srcProf<0) || (srcProf>MAX_PORT_PROFILES-1)) 
			{
				printf ("\nInvalid profile number");
    			return DO_NOT_UPDATE;
			}

			printf ("\nCopy profile %i to profile %i (y/n)? " ,
						srcProf,atoi(ProfNum));
			gets (input);
			sscanf (input,"%c",&confirm);

			if ((confirm=='y') || (confirm=='Y'))
			{
				printf ("\nCopying profile %i to profile %i",
						srcProf,atoi(ProfNum));
				if (memcpyProfile (srcProf,atoi(ProfNum))!=ERROR)
					return UPDATE_IN_FLASH;
				else return DO_NOT_UPDATE;
					
			}
			else
				return DO_NOT_UPDATE;

			break;

		case 98:
				
			ptrTlStr[0] = '\0';  //Null terminate the string
				
			setCpeDefaultPortProfile(atoi(ProfNum));
        return UPDATE_IN_FLASH;

			break;
		
	default:
		break;
	} // switch


    return DO_NOT_UPDATE;

#endif //VTU_O

}


/********************************************************************************\
	Name 	   : getParameters 
	Purpose    : Gets the Parameter value from the user.

	Parameters : 
	no		Name		Type			Description
	--		----		----			-----------
	1. ProfNum	 	   int		Profile number for changing the Port Provisons
    2. ParmType        int      Parameter type to be changed
    3. ParmData        int *    Pointer to the parameter value.

	Return	   : ERROR if a wrong paramater is selected
                 TRUE if correct parameter is selected
	
\********************************************************************************/

int getParameters(int ProfNum, int ParmType, int *ParmData)
{
	ipos_port_profile *tTempPtrPortProfile;
    char    buf[20];

    buf[0]= '\0';
    tTempPtrPortProfile = &sPortProfiles[ProfNum];

    switch (ParmType)
    {
        case INTERLEAVED_PERCENTAGE :
          printf("\n Current Data Path [%d%% Fastpath; %d%% Interleaved]", 
                           tTempPtrPortProfile->PortProvParms.InterleavedPercentage,
                           100 - tTempPtrPortProfile->PortProvParms.InterleavedPercentage);
          printf("\n Enter the new Fastpath Percentage: ");
          break;
        
        case UPSTREAM_MAX_RATE_FAST:
                printf("\n\n Current Value: Max. Data Rate(US-Fast) = %2.2f Mbps", ((float)tTempPtrPortProfile->PortProvParms.UpstreamMaxRateFast* 64)/1000); 
                printf("\n Enter the new Payload Data Rate (1-3125) x 64 Kbps :");
                break;
                    
        case UPSTREAM_MIN_RATE_FAST :
                printf("\n\n Current Value: Min. Data Rate(US-Fast) = %2.2f Mbps", ((float)tTempPtrPortProfile->PortProvParms.UpstreamMinRateFast* 64)/1000); 
                printf("\n Enter the new Payload Data Rate (1-3125) x 64 Kbps :");
                break;
                    
        case UPSTREAM_MAX_RATE_SLOW:
                printf("\n\n Current Value: Max. Data Rate(US-Slow) = %2.2f Mbps", ((float)tTempPtrPortProfile->PortProvParms.UpstreamMaxRateSlow* 64)/1000); 
                printf("\n Enter the new Payload Data Rate (1-3125) x 64 Kbps :");
                break;
                 
        case UPSTREAM_MIN_RATE_SLOW:
                printf("\n\n Current Value: Min. Data Rate(US-Slow) = %2.2f Mbps", ((float)tTempPtrPortProfile->PortProvParms.UpstreamMinRateSlow* 64)/1000); 
                printf("\n Enter the new Payload Data Rate (1-3125) x 64 Kbps :");
                break;

        case UPSTREAM_MAX_INTER_DELAY:
		printf("\n Current Upstream Max. Interleave Delay= %2.1f ms", ((float)tTempPtrPortProfile->PortProvParms.UpstreamMaxInterDelay)/2); 
		printf("\n Enter the new value (in units of 0.5 ms) :"); 
                break;
        
        case DOWNSTREAM_MAX_RATE_FAST:
                printf("\n\n Current Value: Max. Data Rate(DS-Fast) = %2.2f Mbps", ((float)tTempPtrPortProfile->PortProvParms.DownstreamMaxRateFast* 64)/1000); 
                printf("\n Enter the new Payload Data Rate (1-3125) x 64 Kbps :");
                break;

        case DOWNSTREAM_MIN_RATE_FAST:
                printf("\n\n Current Value: Min. Data Rate(DS-Fast) = %2.2f Mbps", ((float)tTempPtrPortProfile->PortProvParms.DownstreamMinRateFast* 64)/1000); 
                printf("\n Enter the new Payload Data Rate (1-3125) x 64 Kbps :");
                break;

        case DOWNSTREAM_MAX_RATE_SLOW:
                printf("\n\n Current Value: Max. Data Rate(DS-Slow) = %2.2f Mbps", ((float)tTempPtrPortProfile->PortProvParms.DownstreamMaxRateSlow* 64)/1000); 
                printf("\n Enter the new Payload Data Rate (1-3125) x 64 Kbps :");
                break;

        case DOWNSTREAM_MIN_RATE_SLOW:
                printf("\n\n Current Value: Min. Data Rate(DS-Slow) = %2.2f Mbps", ((float)tTempPtrPortProfile->PortProvParms.DownstreamMinRateSlow* 64)/1000); 
                printf("\n Enter the new Payload Data Rate (1-3125) x 64 Kbps :");
                break;

        case DOWNSTREAM_MAX_INTER_DELAY:
		printf("\n Current Downstream Max. Interleave Delay= %2.1f ms", ((float)tTempPtrPortProfile->PortProvParms.DownstreamMaxInterDelay)/2); 
		printf("\n Enter the new value (in units of 0.5 ms) :"); 
                break;
        
        case DS_TARGET_NOISE_MARGIN:
                printf("\n Current Downstream Target Noise Margin = %2.1f dB", ((float)tTempPtrPortProfile->PortProvParms.DsTargetNoiseMargin)/2); 
                printf("\n Enter the new value (0-62) x 0.5 dB :"); 
                break;
    
        case US_TARGET_NOISE_MARGIN:
                printf("\n Current Upstream Target Noise Margin = %2.1f dB", ((float)tTempPtrPortProfile->PortProvParms.UsTargetNoiseMargin)/2); 
                printf("\n Enter the new value (0-62) x 0.5 dB :"); 
                break;
          
        case MIN_NOISE_MARGIN:
                printf("\n Current Min. Noise Margin = %2.1f dB", ((float)tTempPtrPortProfile->PortProvParms.MinNoiseMargin)/2); 
                printf("\n Enter the new value (0-62) x 0.5 dB :"); 
                break;

        case UPSTREAM_MIN_PROTECTION:
                printf("\n Current UpStream Min. Protection = %i usec", tTempPtrPortProfile->PortProvParms.UsMinProtection*125); 
                printf("\n Enter the new value (in units of 125usec):"); 
                break;

        case DOWNSTREAM_MIN_PROTECTION:
                printf("\n Current DownStream Min. Protection  = %i usec", tTempPtrPortProfile->PortProvParms.DsMinProtection*125); 
                printf("\n Enter the new value (in units of 125usec):"); 
                break;

        default:
//								EventLog ("getParameters: Unknown ParmType %x",ParmType);
                return ERROR;
    }
    
    // gets(buf);
    scanf("%s",buf);
    fflush(stdout);
    if( (buf[0] == '\n') || (buf[0] == '\0') )
    {
        return ERROR;
    }
    if(sscanf(buf,"%d", ParmData)!=1)  // This is to avoid taking alphabets as input 
        return ERROR;
    return TRUE;
}
                

void updateFlashProf(void)
{
#if 1
	nvramUpdateBlk(2);
#else
	char * pFlashLoc;
	writeProfileToFlash();
	
	pFlashLoc=(char *)(PORT_PROFILE_1-0x10);
	writeChkString(pFlashLoc);
#endif
}

void ife2_per_port_cfg(ipos_port_profile *pProfile)
{
  int     tmp;
  char    buf[100];

  tmp = pProfile->IFE_BRD_CFG.pwrMode;
  printf("\n TX Power............(0=8.5dbm;   1=11.5dbm ) [%d]: ", tmp);
  // gets(buf);
  scanf("%s",buf);
  fflush(stdout); 
  sscanf(buf, "%d", &tmp);
  printf("RXXX temp %d buf %s\n",tmp,buf);
  if(tmp==0||tmp==1)
    pProfile->IFE_BRD_CFG.pwrMode = tmp;
  else
    printf("\n Incorrect Entry!!!");

  tmp = pProfile->IFE_BRD_CFG.rxPathFilterMode;
  printf("\n =================================================");
  printf("\n Filter Types:");
  printf("\n 0 - Internal Path;      1 - K1 External Filter");
  printf("\n 2 - U1 External Filter; 3 - H3 External Filter");
  printf("\n 4 - H4 External Filter ");
  printf("\n =================================================");

  printf("\n RX Path Filter.........................(0-4) [%d]: ", tmp);

  
  // gets(buf);
  scanf("%s",buf);
  fflush(stdout); 
  sscanf(buf, "%d", &tmp);
  if((tmp >= 0) && (tmp <= 4))
    pProfile->IFE_BRD_CFG.rxPathFilterMode = tmp;
  else
    printf("\n Incorrect Entry!!!");

  tmp = pProfile->IFE_BRD_CFG.txPathFilterMode;
  printf("\n TX Path Filter.........................(0-4) [%d]: ", tmp);
  // gets(buf);
  scanf("%s",buf);
  fflush(stdout); 
  sscanf(buf, "%d", &tmp);
  if((tmp >= 0) && (tmp <= 4))
    pProfile->IFE_BRD_CFG.txPathFilterMode = tmp;
  else
    printf("\n Incorrect Entry!!!");
}


struct line_type_descr ui_line_type[] = 
{
    {ADSL1_ANNEX_A,     "ADSL1 DMT ANNEX A "},   
    {ADSL1_ANNEX_B,     "ADSL1 DMT ANNEX B "},
    {ADSL1_ANNEX_C ,    "ADSL1 DMT ANNEX C "},

    {ADSL2_ANNEX_A ,    "ADSL2 DMT ANNEX A "},
    {ADSL2_ANNEX_B ,    "ADSL2 DMT ANNEX B "}, 

    {ADSL2_PLUS_ANNEX_A,    "ADSL2 PLUS ANNEX A"},
    {ADSL2_PLUS_ANNEX_B,    "ADSL2 PLUS ANNEX B"},
    {ADSL2_PLUS_ANNEX_M ,   "ADSL2 PLUS ANNEX M"},
    {ADSL2_PLUS_ANNEX_L,    "ADSL2 PLUS ANNEX L"},

    {VDSL_ANSI,             "VDSL1             "},

    {ITU_G993_2_8A,         "VDSL2 Profile 8A  "},
    {ITU_G993_2_8B,         "VDSL2 Profile 8B  "},
    {ITU_G993_2_8C,         "VDSL2 Profile 8C  "},
    {ITU_G993_2_8D,         "VDSL2 Profile 8D  "},
    {ITU_G993_2_12A,        "VDSL2 Profile 12A "},
    {ITU_G993_2_17A,        "VDSL2 Profile 17A "},
    {ITU_G993_2_30A,        "VDSL2 Profile 30A "},
    {ADSL_T1E1_ISSUE_2,     "ADSL T1E1 ISSUE 2 "},   
    {0,                     "UNKNOWN           "} //End of structure
};


#ifdef CPE_40
void configure_ni(ipos_port_profile *pProfile)
{
    char buf[100];
	int uMode;
	int reset = FALSE;
    
    int val = pProfile->PortProvParms.framingmode;

    if (val == 0x91)
        val = 5;
    else if (val == 0x90)
        val = 3;
    else if (val == 0x81)
        val = 4;
    else if (val == 0x80)
        val = 2;
    else
        val = 1;
    
    printf ("\n Enter selection(1: ATM; 2:PTM; 3:Auto(EFM/PTM); [%d]: ", val );
    
    // Alaska gets(buf);
    scanf("%s",buf);
    fflush(stdout); 

    sscanf(buf, "%d", &val);
    
	// get the old utopia mode. Ifs its ATM and the new one selected is PTM then tell the user to reboot. 
	// same with switching from PTM to ATM
	uMode = oampGetUtopiaMode;

    
    if(val == 1)
		{
        val = 0;
		if (uMode > 0) reset = TRUE;
		}
    else if (val == 2)
		{
        val = 0x80;
		if (uMode == 0) reset = TRUE;
		}
    else if (val ==3)
		{
        val = 0x90;
		if (uMode == 0) reset = TRUE;
		}
    else if (val ==4)
		{
        val = 0x81;
		if (uMode == 0) reset = TRUE;
		}
    else if (val ==5)
		{
        val = 0x91;
		if (uMode == 0) reset = TRUE;
		}



    
#ifdef INI_SUPPORT    
    if( (val == 0x90) || (val == 0x80) || (val == 0)) 
    {
        pProfile->PortProvParms.framingmode = val;
		if (reset)
			printf("CPU must be reset before chenge takes effect\n");

		// set the sys data base here for CPE4.. make optionMask same as framing mode. 

		if (val == 0x90)
			{
			oampSetUtopiaMode(0xc0);
			}
		else
			oampSetUtopiaMode(val);

    } else if ( (val == 0x81) || (val == 0x91) )
    {
        pProfile->PortProvParms.framingmode = val;
        printf("Invalid Framing Mode");
		// set the sys data base here for CPE4. 
		if (val == 0x91)
			{
			oampSetUtopiaMode(0xc1);
			}
		else
			oampSetUtopiaMode(val);

    }
    else 
    {
        printf("Invalid Framing Mode");
    }
#else
    if (val == 0)
    {
		oampSetUtopiaMode(val);
        pProfile->PortProvParms.framingmode = val;
		if (reset)
			printf("CPU must be reset before chenge takes effect\n");
    }
    else 
    {
        printf("Invalid Framing Mode");
    }
#endif


}
#endif
/* END_OF_FILE */
