/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/


/*****************************************************************************
 *
 * Filename:
 * ---------
 *   $Workfile: net_if.h $
 *
 * Project:
 * --------
 *
 *
 * Description:
 * ------------
 *   Network driver interface header file
 *
 * Author:
 * -------
 *   Hs Huang
 *
 * Last changed:
 * -------------
 * $Author:
 *
 * $Modtime:
 *
 * $Revision:
****************************************************************************/

/**************************************************************************** 
Network Driver: Interface 
****************************************************************************/

#ifndef X_NET_IF_H
#define X_NET_IF_H

#include "x_os.h"
#include "x_assert.h"
#include "x_typedef.h"

#include "u_net_drv_if.h"
#include "u_net_oid.h"

/****************************************************************************
** Constant definitions
****************************************************************************/
#define CONFIG_WLAN_WPD 0
#define CONFIG_DTCP 0
#define CONFIG_CHKSUM 1

#define NET_SUSPEND             0xFFFFFFFFUL    /* network OS suspend */
#define NET_DRV_DBG             1


/* network driver ID */
typedef enum
{
    DRVID_NET_DOCSIS_RFI,
    DRVID_NET_ETHERNET_802_3,
    DRVID_NET_WIRELESS_802_11,
    DRVID_NET_USB,
    DRVID_NET_SERIAL,
    DRVID_NET_LOOPBACK
} NET_DRV_ID_T;


/****************************************************************************
** Structure and Type definitions
****************************************************************************/

//-----------------------------------------------------------------------------
// funtcion error type
//-----------------------------------------------------------------------------
#define E_NET_OK                            ((INT32)    0)
#define E_NET_NOT_INIT                      ((INT32)   -1)
#define E_NET_ALREADY_INIT                  ((INT32)   -2)
#define E_NET_INV_SOURCE                    ((INT32)   -3)
#define E_NET_INV_SET_INFO                  ((INT32)   -4)
#define E_NET_STATE_MISMATCH                ((INT32)   -5)
#define E_NET_OUT_OF_RESOURCE               ((INT32)   -6)
#define E_NET_NOT_ALLOC_RESOURCE            ((INT32)   -7)

#define E_NET_INV_ARG                       ((INT32)   -10)
#define E_NET_INV_ARG1                      ((INT32)   -11)
#define E_NET_INV_ARG2                      ((INT32)   -12)
#define E_NET_INV_ARG3                      ((INT32)   -13)
#define E_NET_INV_ARG4                      ((INT32)   -14)
#define E_NET_INV_ARG5                      ((INT32)   -15)
#define E_NET_INV_ARG6                      ((INT32)   -16)

#define E_NET_NO_EFFECT                     ((INT32)   -1000)
#define E_NET_GENERAL_FAIL                  ((INT32)   -10000)


#define NET_DRV_NO_RESOURCE                 ((INT32)   -15)
#define NET_DRV_NO_ASSOCICATION             ((INT32)   -16)


#if 0
// Copy from linux Errno-base.h
#define	EPERM		 			1	/* Operation not permitted */
#define	ENOENT		 			2	/* No such file or directory */
#define	ESRCH		 			3	/* No such process */
#define	EINTR		 			4	/* Interrupted system call */
#define	EIO		 	 			5	/* I/O error */
#define	ENXIO		 			6	/* No such device or address */
#define	E2BIG		 			7	/* Argument list too long */
#define	ENOEXEC		 			8	/* Exec format error */
#define	EBADF		 			9	/* Bad file number */
#define	ECHILD					10	/* No child processes */
#define	EAGAIN					11	/* Try again */
#define	ENOMEM					12	/* Out of memory */
#define	EACCES					13	/* Permission denied */
#define	EFAULT					14	/* Bad address */
#define	ENOTBLK					15	/* Block device required */
#define	EBUSY					16	/* Device or resource busy */
#define	EEXIST					17	/* File exists */
#define	EXDEV					18	/* Cross-device link */
#define	ENODEV					19	/* No such device */
#define	ENOTDIR					20	/* Not a directory */
#define	EISDIR					21	/* Is a directory */
#define	EINVAL					22	/* Invalid argument */
#define	ENFILE					23	/* File table overflow */
#define	EMFILE					24	/* Too many open files */
#define	ENOTTY					25	/* Not a typewriter */
#define	ETXTBSY					26	/* Text file busy */
#define	EFBIG					27	/* File too large */
#define	ENOSPC					28	/* No space left on device */
#define	ESPIPE					29	/* Illegal seek */
#define	EROFS					30	/* Read-only file system */
#define	EMLINK					31	/* Too many links */
#define	EPIPE					32	/* Broken pipe */
#define	EDOM					33	/* Math argument out of domain of func */
#define	ERANGE					34	/* Math result not representable */
#endif

/****************************************************************************
** External variable
****************************************************************************/

/****************************************************************************
** Export Macro
****************************************************************************/

/****************************************************************************
** External Network API, from wlan_os.h temporally
****************************************************************************/
void vNetTestGpioOut(INT32 i4Val);
void vNetTestGpioToggle(void);
void vNetTestGpioInit(void);
void vNetDelay1us(UINT32 u4Value);
void *pvNetAlignAddr(void *pAddr, UINT32 u4Align);
UINT32 u4NetGetTimeTick(void);
INT32 MW_NET_Init(void);

#endif /* _NET_IF_H_ */
