#include"../../linux/net/adi/inc/stackios.h"
#include "../inc/appdefines.h"
#include "../inc/apptypes.h"
#include "../inc/emaclib.h"

INT16 emacGetLink(emacLS* pstLStruct, UCHAR* paucMessage)
{
    LONG sockfd;
    struct ifreq ifr;

    bzero(&ifr, sizeof(ifr));

    if(strlen(pstLStruct->aucIfName) == 0)
    {
        strcpy(paucMessage, "Interface Name Required");
        return FAILURE;
    }

    ifr.ifr_ifru.ifru_data = (char *)pstLStruct;
    strncpy(ifr.ifr_name, pstLStruct->aucIfName, IFNAMSIZ);

    if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
    {
        strcpy(paucMessage, "Unable to Open Socket");
        return FAILURE;
    }
    else
        ioctl(sockfd, GET_EMAC_LINK, (struct ifreq *)&ifr);

    return SUCCESS;
}

INT16 emacSetLink(emacLS* pstLStruct, UCHAR* paucMessage)
{
    LONG sockfd;
    struct ifreq ifr;

    bzero(&ifr, sizeof(ifr));

    if(strlen(pstLStruct->aucIfName) == 0)
    {
        strcpy(paucMessage, "Interface Name Required");
        return FAILURE;
    }

    ifr.ifr_ifru.ifru_data = (char *)pstLStruct;
    strncpy(ifr.ifr_name, pstLStruct->aucIfName, IFNAMSIZ);

    if((sockfd = socket( AF_INET, SOCK_DGRAM,0 )) < 0)
    {
        strcpy(paucMessage, "Unable to open socket");
        return FAILURE;
    }
    else
        ioctl(sockfd, SET_EMAC_LINK, (struct ifreq *)&ifr);

    close(sockfd);
    return SUCCESS;
}
