/*******************************************************************************
 * (c) Copyright 2015 Microsemi Corporation.  All rights reserved.
 *
 *
 *
 * SVN $Revision: $
 * SVN $Date: $
 */

#ifndef NETWORK_SETTINGS_H_
#define NETWORK_SETTINGS_H_

#include <api_oam_sdk/common/constants/inc/mr_constants.h>
#include "network_utilities.h"

/*
 * @brief Read the network settings from NVM into array
 *
 * @param[out] networkConfig Pointer to an array of networkConfig_t to store the network settings
 * @return 0 if no error occurred, a non-zero error code otherwise
 *
 * This function tries to read the network settings from Non Volatile Memory (NVM)
 * and copy the values into the supplied storage array. There can be PHY_COUNT
 * network interfaces so the supplied array must have that number of elements.
 * If the there is no network settings in NVM or the NVM data is corrupt then
 * default values are returned and a the NVM updated with the defaults.
 */
int verifyNvmNetworkSettings(networkConfig_t networkConfig[PHY_COUNT]);

/*
 * @brief Reconfigure the selected network Interface with latest settings
 *
 * @param[in] ifNum The number of the interface to reconfigure. 0,1..PHY_COUNT
 *
 * This function can be called to reconfigure the selected network interface
 * after the network settings for that interface have been changes by the
 * user.
 */
void reconfigNetIf(uint8_t ifNum);

/*
 * @brief Configure the MetRoam Ethernet interfaces to operate with lwIP
 *
 * @param[in] param Must be a pointer to an array of networkConfig_t containing current network settings
 *
 * This function is intended to be called as a parameter of the LWIP initialisation function 'tcpip_init'
 * It will carry out the initialisation necessary for the MetRoam Ethernet interfaces to
 * operate with lwip. It is possible for one or both of these interfaces to be disabled
 * for management.
 */
void configureEthernetInterfaces(void * param);

/*
 * @brief Returns true if the selected interface is enabled for management
 *
 * @param[in] ifNum The number of the interface to reconfigure. 0,1..PHY_COUNT
 *
 * Returns true if the selected interface is enabled for management
 */
boolean_t is_interface_active(uint8_t ifNum);

/*
 * @brief Check the Ethernet Link status and inform lwIP of changes
 *
 * @param[in]	lastStatus An array of length PHY_COUNT used to store the last link status value
 * @param[in]	networkConfig Pointer to an array of networkConfig_t which holds the network settings
 *
 * This functions is intended to be called as part of a periodic polling loop
 * to monitor the status of all the Ethernet links. If a link is detected a
 * having gone up or down the lwip Stack is notified accordingly.
 */
void netMonitorLinkStatus(uint32_t lastStatus[PHY_COUNT], networkConfig_t networkConfig[PHY_COUNT]);

void setLinkUp(uint8_t ifNum);

const char* printfIPAddr(uint32_t ip, char* buf);
#endif /* NETWORK_SETTINGS_H_ */
