/* 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.
 *
 *****************************************************************************/

/*----------------------------------------------------------------------------*/
/*! @file c_net_config.h
 * $RCSfile: $
 * $Revision: #1 $
 * $Date: 2015/11/10 $
 * $Author: dtvbm11 $
 *
 * @par Description:
 *      network configuration related functions
 */
/*----------------------------------------------------------------------------*/
/*!
* @defgroup    groupMW_INET INET API
* @ingroup     groupMW
* @brief       Provide an external API about network.
* %INET API would be used by user who wants to use network.
*              The Socket API provided by Network module is standard BSD socket API.
*              It provides the interface for an application program
*              to develop a network application. 
*              And this document is used for application to start network stack
*              and configure device IP address, and gives user a brief view
*              on how to start up network module and how to get/set network interface.
* 
* @{
*/

#ifndef C_NET_CONFIG_H
#define C_NET_CONFIG_H

#include "u_common.h"
#include "u_net_common.h"
#include "u_dhcpc_api.h"
#include "u_net_ni_if.h"
#include "u_http_firmware_upgrade.h"

/*!
 * @brief  network module initialization
 * @return return the error code
 * @retval NET_OK       - successed
 * @retval else value   - failure
 */
extern INT32    c_net_network_init(VOID);

/*!
 * @brief  network module de-initialization
 * @return return the error code
 * @retval NET_OK       - successed
 * @retval else value   - failure
 */
extern INT32    c_net_network_deinit(VOID);

/*!
 * @brief  set interface type (switch wifi/eth), use IF_TYPE_ETHERNET, IF_TYPE_IEEE80211 etc.
 * @return return the error code
 * @retval NET_OK       - successed
 * @retval else value   - failure
 */
extern INT32 c_net_set_if_type(INT32 i4_iftype);

/*!
 * @brief  configure a network interface
 * @param in psz_name    - interface name string, ex: "eth0", "wi0" etc.
 * @param in ui4_address - IP address (big-endian UINT32)
 * @param in ui4_netmask - netmask (big-endian UINT32)
 * @param in ui4_gw      - gateway IP address (big-endian UINT32)
 * @return return the error code
 * @retval NET_OK       - successed
 * @retval else value   - failure
 */
extern INT32    c_net_ip_config(CHAR *psz_name, UINT32 ui4_address, UINT32 ui4_netmask, UINT32 ui4_gw);

/*!
 * @brief  configure DNS server address
 * @param in ui4_dns1    - primary DNS server IP address (big-endian UINT32)
 * @param in ui4_dns2    - secondary DNS server IP address (big-endian UINT32)
 * @return return the error code
 * @retval NET_OK       - successed
 * @retval else value   - failure
 */
extern INT32    c_net_dns_config(UINT32 ui4_dns1, UINT32 ui4_dns2);

/*!
 * @brief  set system's host-name
 * @param in ps_hostname   - host name string
 * @return VOID
 */
extern VOID     c_net_set_hostname(CHAR *ps_hostname);

/*!
 * @brief  enable current network interface (to be actived)
 * @return return the error code
 * @retval NET_OK       - successed
 * @retval else value   - failure
 */
extern INT32 c_net_enable (VOID);

/*!
 * @brief  disable current network interface (to be actived)
 * @return return the error code
 * @retval NET_OK       - successed
 * @retval else value   - failure
 */
extern INT32 c_net_disable (VOID);

/* DLNA DHCP client */
/*!
 * @brief  dhcp module initialization
 * @return return the error code
 * @retval NET_OK       - successed
 * @retval else value   - failure
 */
extern INT32   c_dhcpc_init(VOID);

/*!
 * @brief  dhcp module de-initialization
 * @return return the error code
 * @retval NET_OK       - successed
 * @retval else value   - failure
 */
extern INT32   c_dhcpc_deinit(VOID);

/*!
 * @brief start a dhcp or autoip request.
 * @param in ps_ni_name    - the ni(Network Interface) name string, like "eth0", to request ip
 * @param in fn            - the callback to inform caller state changed
 * @return return the error code
 * @retval DHCPC_R_NOT_INIT       - module not init
 * @retval DHCPC_R_NI_NOT_EXIST   - network interface not exist
 * @retval DHCPC_R_MAP_FULL       - can not allocate new mapping entry (no dhcp client space)
 * @retval DHCPC_R_START_FAILED   - start request failed
 * @retval DHCPC_R_OSAI_FAILED    - internal error
 * @retval DHCPC_R_OK             - start ok
 */
extern INT32   c_dhcpc_start(CHAR *ps_ni_name, x_dhcpc_nfy_fct fn);

/*!
 * @brief get ip address information (DHCP)
 * @param in ps_ni_name    - the network interface name string to query ip
 * @param out pt_info      - the storage to save query result
 * @return return the error code
 * @retval DHCPC_R_NOT_INIT           - module not init
 * @retval DHCPC_R_NI_NOT_EXIST       - network interface not exist
 * @retval DHCPC_R_NO_REQUEST_ID      - request id not exist
 * @retval DHCPC_R_INVALID_ARGS       - argument storage is empty
 * @retval DHCPC_R_INTERNAL_FAILED    - internal error
 * @retval DHCPC_R_OK                 - start ok
 */
extern INT32   c_dhcpc_get_info(CHAR *ps_ni_name, MT_DHCP4_INFO_T *pt_info);

/*!
 * @brief request ip again
 * @param in ps_ni_name   - the network interface name string to restart request
 * @return return the error code
 * @retval DHCPC_R_NOT_INIT       - module not init
 * @retval DHCPC_R_NI_NOT_EXIST   - network interface not exist
 * @retval DHCPC_R_NO_REQUEST_ID  - can not find request ID
 * @retval DHCPC_R_RESTART_FAILED - restart failed
 * @retval DHCPC_R_OK             - restart ok
 */
extern INT32   c_dhcpc_restart(CHAR *ps_ni_name);

/*!
 * @brief  stop IP request
 * @param in ps_ni_name   - the network interface name string to stop request
 * @return return the error code
 * @retval DHCPC_R_NOT_INIT       - module not init
 * @retval DHCPC_R_NO_REQUEST_ID  - can not find request ID
 * @retval DHCPC_R_NI_NOT_EXIST   - network interface not exist
 * @retval DHCPC_R_OSAI_FAILED    - internal error
 * @retval DHCPC_R_STOP_FAILED    - stop failed
 * @retval DHCPC_R_OK             - stop ok
 ----------------------------------------------------------------------------*/
extern INT32   c_dhcpc_stop(CHAR *ps_ni_name);

/*!
 * @brief ping utility, user may use this API to verify remote host is online or not.
 * @param in ps_ip     - dot format IPv4 address string, ex "192.168.1.1"
 * @param in i2_len    - payload size (send data size)
 * @param in i2_wait   - maximum wait time (in seconds)
 * @param in notify_fn - notify callback
 */
extern VOID c_net_ping_v4(CHAR * ps_ip,
                          INT32  i4_len,
                          INT16  i2_wait,
                          VOID (*notify_fn) (INT16 i2_rsp_time));

/* configure socket block mode */
/*!
 * @brief configure socket as nonblocking mode
 * @param in sock - socket file-description to config
 * @return return the error code
 * @retval NET_OK - ok
 * @retval else   - failed
 */
extern int c_net_socket_nonblocking(int sock);

/*!
 * @brief configure socket as blocking mode
 * @param in sock - socket file-description to config
 * @return return the error code
 * @retval NET_OK - ok
 * @retval else   - failed
 */
extern int c_net_socket_blocking(int sock);

/*!
 * @brief query current socket mode
 * @param in sock - socket file-description to query
 * @return return the error code
 * @retval NET_OK - ok
 * @retval else   - failed
 */
extern int c_net_get_socket_mode(int sock);

/* NET NI C_api */
/*!
 * @brief Allocate a new layer 2 switch
 * @param in ps_name   - the brief name of switch (maximum length 8 bytes)
 * @return L2_SWITCH_T*
 * @retval NULL     - allocate new switch failed
 * @retval else     - address of new switch
 */
extern L2_SWITCH_T *c_net_switch_new(CHAR *ps_name);

/*!
 * @brief Setup default Network Interface for layer 2 switch
 * @param in pt_Switch    - the switch to install default NI
 * @param in i4_NiHandle  - NI Handle
 * @return return the error code
 * @retval NET_OK              - for install ok
 * @retval NET_SWITCH_INVALID  - invalid arguments
 */
extern INT32 c_net_switch_add_default_ni(L2_SWITCH_T *pt_Switch, INT32 i4_NiHandle);

/*!
 * @brief Install NI to layer 2 switch
 * @param in pt_Switch   - the switch to install NI
 * @param in i4_NiHandle - NI handle
 * @return return the error code
 * @retval NET_OK             - for install ok
 * @retval NET_SWITCH_INVALID - failed
 */
extern INT32 c_net_switch_add_ni(L2_SWITCH_T *pt_Switch, INT32 i4_NiHandle);

/*!
 * @brief Add learning entry into learning table
 * @param in pt_Switch    - the switch to add learning entry
 * @param in pac_Mac      - Source Mac address
 * @param in i4_NiHandle  - Source NI handle
 * @return return the error code
 * @retval NET_OK                   - for install ok
 * @retval NET_SWITCH_INVALID       - arguments is invalid
 * @retval NET_SWITCH_MALLOC_FAILED - memory allocate failed
 */
extern INT32 c_net_switch_add_learn_entry (L2_SWITCH_T *pt_Switch, UINT8 *pac_Mac, INT32 i4_NiHandle);

/*!
 * @brief Find learning entry in learning tanle
 * @param in pt_Switch - the switch to find learning entry
 * @param in pac_Mac   - The DA MAC
 * @return return the error code
 * @retval >0  - found specify DA MAC in learning table
 * @retval 0   - not found
 * @retval <0  - invalid arguments
 */
extern INT32 c_net_swtich_find_learn_entry(L2_SWITCH_T *pt_Switch, UINT8 *pac_Mac);

/*!
 * @brief Lookup internal learning table to send out packet
 * @param in pt_Switch   - the switch to send packet
 * @param in pt_packet   - the packet to send out
 * @param in i4_NiHandle - NI handle for lookup learning table
 * @return return the error code
 * @retval NET_OK     - send ok
 * @retval NET_FAILED - send failed
 */
extern INT32 c_net_switch_transmit_packet(L2_SWITCH_T *pt_Switch, PKT_BUFF_T *pt_packet, INT32 i4_NiHandle);

/*!
 * @brief Create new NI interface
 * @param in ps_name   - Name of NI
 * @param in i4_iftype - the type of network interface
 * @return new NET_NI_T*
 * @retval NULL  - for failed,
 * @retval !NULL - address of new NI
 */
extern NET_NI_T *c_net_ni_new(CHAR *ps_name, INT32 i4_ifType);

/*!
 * @brief The API for upper layer interface to install low level driver
 * @param in pt_ni  - the NI to install driver
 * @param in pf_fn  - driver entry point
 * @return return the error code
 * @retval NET_OK      - send ok
 * @retval NET_FAILED  - send failed
 */
extern INT32 c_net_ni_install_drv_entry(NET_NI_T *pt_ni, NetworkDriverEntry pf_fn);

/*!
 * @brief The API to start NI and network driver
 * @param in pt_ni - the NI to start up
 * @return return the error code
 * @retval NET_OK     - ok
 * @retval NET_FAILED - send failed
 */
extern INT32 c_net_ni_start(NET_NI_T *pt_ni);

/*!
 * @brief Change default NI TransmitPacket API
 * @param in pt_ni  - the NI to change transmit function
 * @param in pf_fn  - new transmit function
 * @return return the error code
 * @retval NET_OK      - send ok
 * @retval NET_FAILED  - send failed
 */
extern INT32 c_net_ni_install_transmit_packet_callback(NET_NI_T *pt_ni, net_ni_transmit_pkt pf_fn);

/*!
 * @brief Change default NI receivePacket API
 * @param in pt_ni  - the NI to change receive function
 * @param in pf_fn  - new receive function
 * @return return the error code
 * @retval NET_OK     - send ok
 * @retval NET_FAILED - send failed
 */
extern INT32 c_net_ni_install_receive_packet_callback(NET_NI_T *pt_ni, net_ni_receive_pkt pf_fn);

/*!
 * @brief The inform API for driver to inform upper layer interface to receive packet for further process
 * @param in pt_drv  - the driver to use
 * @param in pt_pkb  - point to received packet
 * @return return the error code
 * @retval NET_OK      - send ok
 * @retval NET_FAILED  - send failed
 */
extern INT32 c_net_ni_packet_indication(NET_DRV_IF_T *pt_drv, PKT_BUFF_T *pt_pkb);

/*!
 * @brief The trasnmit complete API
 * @param in pt_drv  - the driver interface to call tx_complete
 * @param in pt_pkb  - the packet to release
 * @return return the error code
 * @retval NET_OK     - send ok
 * @retval NET_FAILED - send failed
 */
extern INT32 c_net_ni_tx_completed(NET_DRV_IF_T *pt_drv, PKT_BUFF_T *pt_pkb);

/*!
 * @brief The NI default Receive Packet function
 * @param in pt_ni    - the NI to receive packet
 * @param in pt_buff  - packet
 * @return return the error code
 * @retval NET_OK      - send ok
 * @retval NET_FAILED  - send failed
 */
extern INT32 c_net_ni_rx_packet(NET_NI_T *pt_ni, PKT_BUFF_T *pt_buff);

/*!
 * @brief Default NI Transmit Packet function
 * @param in pt_ni   - the NI to transmit packet
 * @param in pt_buff - the packet buffer to send out
 * @return return the error code
 * @retval NET_OK     - send ok
 * @retval NET_FAILED - send failed
 */
extern INT32 c_net_ni_tx_packet(NET_NI_T *pt_ni, PKT_BUFF_T *pt_buff);

/*!
 * @brief get NI interface struct by network interface name
 * @param in ps_name   - Name of NI
 * @return existed NI struct 
 * @retval NULL  - for failed,
 * @retval !NULL - address of existed NI
 */
extern NET_NI_T *c_net_ni_get_by_name(CHAR *ps_name);

/*!
 * @brief Free NI list resource
 */
extern VOID c_net_ni_list_reset(VOID);

/*!
 * @brief set interface psz_name's MAC address
 * @param in psz_name   - network ineterface name to set
 * @param in pc_mac     - MAC address char array
 * @return return the error code
 * @retval NET_OK     - ok
 * @retval NET_FAILED - failed
 */
extern INT32 c_net_ni_set_mac(CHAR *psz_name, CHAR *pc_mac);

/*!
 * @brief save interface psz_name's MAC address into persistent storage
 * @param in psz_name   - network ineterface name to set
 * @param in pui1_mac   - MAC address UINT8 array
 * @return return the error code
 * @retval NET_OK     - ok
 * @retval NET_FAILED - failed
 */
extern INT32 c_net_ni_save_mac(const CHAR *psz_name, UINT8 *pui1_mac);

/*!
 * @brief get interface psz_name's MAC address
 * @param in psz_name    - network ineterface name to query
 * @param out pc_mac     - MAC address char array
 * @return return the error code
 * @retval NET_OK     - ok
 * @retval NET_FAILED - failed
 */
extern INT32 c_net_ni_get_mac(CHAR *psz_name, CHAR *pac_mac);

/*!
 * @brief Configure interface type
 * @param in pt_ni   - NI * to set
 * @param i4_type    - type to set
 * @return return the error code
 * @retval NET_OK     - ok
 * @retval NET_FAILED - failed
 */
extern INT32 c_net_ni_set_if_type(NET_NI_T *pt_ni, INT32 i4_type);

/*!
 * @brief return ni list
 * @return NET_NI_T*
 * @retval NULL  - for failed,
 * @retval !NULL - address of existed NI
 */
extern NET_NI_T *c_net_ni_list_get(VOID);

/*!
 * @brief set IP and interface mapping
 * @param in pt_ni1  - assocate ni 1
 * @param in pt_ni2  - assocate ni 2
 * @return return the error code
 * @retval NET_OK  - ok
 * @retval others  - failed
 */
extern INT32 c_net_ni_add_assocate_ni(NET_NI_T *pt_ni1, NET_NI_T *pt_ni2);

/*!
 * @brief Get request OID value from specify Ni
 * @param in ps_niName  - ni name
 * @param in i4_cmd     - ni command 
 * @param in pv_param   - result
 * @return return the error code
 * @retval NET_OK      - no error
 * @retval NET_INV_ARG - not support OID
 * @retval others      - failed
 * @note the memory is allocated by caller
 */
extern INT32 c_net_ni_get(CHAR *ps_niName, INT32 i4_cmd, VOID *pv_param);

/*!
 * @brief Set request OID value from specify Ni
 * @param in ps_niName  - ni name
 * @param in i4_cmd     - ni command
 * @param in pv_param   - value to set
 * @return return the error code
 * @retval NET_OK      - no error
 * @retval NET_INV_ARG - not support OID
 * @retval others      - failed
 */
extern INT32 c_net_ni_set(CHAR *ps_niName, INT32 i4_cmd, VOID *pv_param);

/*!
 * @brief Add multicast IP address to interface
 * @param in ps_niName - network interface name
 * @param in ui4_ip    - the IP address (network order/big-endian)
 * @return return the error code
 * @retval NET_OK           - ok
 * @retval NET_NI_NOT_EXIST - ni not exist
 */
extern INT32 c_net_if_join(const CHAR* ps_niName, UINT32 ui4_ip);

/*!
 * @brief leave a multicast group
 * @param in ps_niName - network interface name
 * @param in ui4_ip    - the IP address (network order/big-endian)
 * @return return the error code
 * @retval NET_OK           - ok
 * @retval NET_NI_NOT_EXIST - ni not exist
 */
extern INT32 c_net_if_leave(const CHAR* ps_niName, UINT32 ui4_ip);

/*!
 * @brief get multicast list
 * @param in ps_niName  - ni name
 * @param out paui4_ip  - local buffer for multicast IP
 * @param in i4_size    - size of paui4_ip ?
 * @return the size of ip lists
 */
extern INT32 c_net_if_multi_list(const CHAR* ps_niName, UINT32 *paui4_ip, INT32 i4_size);

/*!
 * @brief register callback function for network interface state changing
 * @param in ps_niName  - network interface name
 * @param in e_ev       - event tag
 * @param in pf_notify  - callback privied by caller to inform when network interface state changed
 * @return return the error code
 * @retval NET_OK           - ok
 * @retval others           - failed
 */
extern INT32 c_net_ni_reg_ev_notify(CHAR *ps_ni_name, NI_DRV_EV_T e_ev, ni_ev_notify_fnct pf_notify);
extern INT32 c_net_ni_reg_ev_notify_ifname(CHAR *ps_ni_name, NI_DRV_EV_T e_ev, ni_ev_notify_fnct_ifname pf_notify);

/*!
 * @brief un-register callback function for network interface state changing
 * @param in ps_niName  - network interface name
 * @param in e_ev       - event tag
 * @param in pf_notify  - callback privied by caller to inform when network interface state changed
 * @return return the error code
 * @retval NET_OK           - ok
 * @retval others           - failed
 */
extern INT32 c_net_ni_unreg_ev_notify(CHAR *ps_ni_name, NI_DRV_EV_T e_ev, ni_ev_notify_fnct pf_notify);

/*!
 * @brief send ni monitor event to call register callback functions user registed.
 * @param in pt_ni      - network interface ni*
 * @param in e_ev       - event tag
 * @return return the error code
 * @retval NET_OK           - ok
 * @retval others           - failed
 */
extern INT32 c_net_ni_ev_send(NET_NI_T *pt_ni, NI_DRV_EV_T e_ev);

/*!
 * @brief clear the DNS caches
 */
extern VOID c_net_clean_dns_cache(VOID);

/*!
 * @brief abort current ctx action
 * @param in pt_ctx   - active http context
 */
extern VOID                         c_http_cmd_abort(HTTP_CTX_T *pt_ctx);

/*!
 * @brief de-allocate a http download context 
 * @param in pt_ctx   - the ctx to de-allocate
 */
extern VOID                         c_http_cmd_del_ctx(HTTP_CTX_T *pt_ctx);

/*!
 * @brief get download file size
 * @param in pt_ctx   - current http context
 * @return the size of content_length in http response
 */
extern UINT32                       c_http_cmd_get_content_length(HTTP_CTX_T *pt_ctx);

/*!
 * @brief get tag form xml response. 
 * @param in pt_ctx      - active http context
 * @param in ps_tag_name - the tag name
 * @return return tag's value
 * @retval NULL   - not found
 */
extern CHAR *                       c_http_cmd_get_ctx_tag_result(HTTP_CTX_T *pt_ctx, CHAR *ps_tag_name);

/*!
 * @brief send an read binary data command to internal thread
 * @param in pt_ctx   - active http context
 * @return return the error code
 * @retval HTTP_RET_OK                     - ok
 * @retval HTTP_RET_OSAI_SEND_MSG_FAILED   - OSAI failed
 */
extern HTTP_RET_CODE_T              c_http_cmd_get_method(HTTP_CTX_T *pt_ctx);

/*!
 * @brief get current download size
 * @param in pt_ctx   - current http context
 * @return return current received size (bytes)
 */
extern UINT32                       c_http_cmd_get_recvd_size(HTTP_CTX_T *pt_ctx);

/*!
 * @brief Allocate a new http download context 
 * @param in ps_url            - the server url
 * @param in fn                - caller provided notify API
 * @param in pac_buff          - caller provided buffer to hold data
 * @param in i4_ac_buffer_size - caller provided buffer size
 * @return return a new http context
 * @retval NULL  - failed.
 */
extern HTTP_CTX_T *                 c_http_cmd_new_ctx(CHAR *ps_url, x_http_fw_dn_read_nfy fn, CHAR *pac_buffer, INT32 i4_ac_buffer_size);

/*!
 * @brief Do a http post-method request 
 * @param in pt_ctx              - active context
 * @param in ps_request_content  - the XML content to send
 * @param in e_rsp_type          - expect response data format
 * @return return the error code
 * @retval HTTP_RET_OK                    - ok
 * @retval HTTP_RET_OSAI_SEND_MSG_FAILED  - OSAI failed
 */
extern HTTP_RET_CODE_T              c_http_cmd_post_method(HTTP_CTX_T *pt_ctx, CHAR *ps_request_content);

/*!
 * @brief http download control thread
 */
extern VOID                         c_http_cmd_upgrade_module_init(VOID);

/*!
 * @brief remove non base64 mapping char from base64 encode content
 * @param in pv_base64_input  - base64 encoded content
 * @param in i4_len           - content length
 * @return return code indicated contain non-base 64 char or not
 * @retval 0     - didn't contain non-base 64 char
 * @retval else  - contain non-base 64 content
 */
extern INT32                        c_http_cmd_fix_non_base64_char(CHAR* pv_base64_input, INT32 i4_len);

/*!
 * @brief parse download xml file
 * @param in pt_ctx         - the context to save parse result
 * @param in pv_in_xml      - downloaded xml content
 * @param in i4_in_xml_size - downloaded xml content size
 * @return parsed result in pt_ctx->pv_rsp
 * @retval HTTP_RET_WRONG_XML_FMT  - error
 * @retval 0                       - ok
 */
extern HTTP_RET_CODE_T              c_http_cmd_parse_xml(HTTP_CTX_T *pt_ctx, VOID *pv_in_xml, INT32 i4_in_xml_size);

/*!
 * @brief get http response status code
 * @param in pt_ctx   - the context to query
 * @return HTTP_RESPONSE_STATUS_CODE_T indicate HTTP standard response code
 */
extern HTTP_RESPONSE_STATUS_CODE_T  c_http_cmd_get_rsp_status(HTTP_CTX_T *pt_ctx);

/** 
 * Base64 utility
 */
/*!
 * @brief encode data to base64
 * @param in pv_in_data             - input data pointer
 * @param in i4_pv_in_data_size     - input data length
 * @param out pac_out_data          - output data
 * @param out i4_pac_out_data_size  - output data length ?
 * @return output data length or error code
 * @retval >= 0  - indicate output data length
 * @retval < 0   - indicate error
 */
extern INT32 c_base64_encode(const VOID *pv_in_data, INT32 i4_pv_in_data_size, VOID *pac_out_data, INT32 i4_pac_out_data_size);

/*!
 * @brief decode data from base64
 * @param in ps_in_str             - input data pointer
 * @param in i4_ps_in_str_len      - input data length
 * @param out pv_out_data          - output data
 * @param out i4_pv_out_data_size  - output data length ?
 * @return output data length or error code
 * @retval >= 0  - indicate output data length
 * @retval < 0   - indicate error
 */
extern INT32 c_base64_decode(const VOID* ps_in_str, INT32 i4_ps_in_str_len, VOID *pv_out_data, INT32 i4_pv_out_data_size);

/** 
 * Query software version
 */
/*!
 * @brief get ave_tcp tag string (version info string)
 * @return ave_tcp tag string
 */
extern CHAR *c_ave_tcp_tag(VOID);

/*!
 * @brief get dlna tag string (version info string)
 * @return dlna tag string
 */
extern CHAR *c_nflc_dlna_tag(VOID);

/*!
 * @brief get MAC by IP address (localhost or other hosts' on the same sub-net addresses)
 * @param in ps_ip     - the IP address string (dot format IPv4) to query
 * @param out puac_mac - an array of unsigned char save MAC address
 * @return return the error code
 * @retval NET_OK     - OK
 * @retval NET_FAILED - no in ARP tables
 * @retval else       - not to be on the same subnet
 */
extern INT32 c_net_get_mac_by_ip (const CHAR *ps_ip, UCHAR *puac_mac);

/*!
 * @brief register callback function for network can initialize notify
 * @param in pf_nfy   - callback function
 * @param in ui4_tag  - callback tag parameter
 * @return return the error code
 * @retval NET_OK     - OK
 * @retval NET_FAILED - register error
 */
extern INT32 c_net_network_reg_nfy (x_network_status_nfy pf_nfy, UINT32 ui4_tag);



/*!
 * @brief manually configure IPv6 address and default gateway
 *
 */
extern INT32 c_net_ip_v6_config(CHAR *psz_name, UINT32 ui4_prefix_len, CHAR* pt_ipv6_addr, CHAR* pt_ipv6_gw);

/*!
 * @brief manually configure IPv6 DNS
 *
 */
extern INT32 c_net_dns_v6_config(CHAR* pc_dns1, CHAR* pc_dns2);

/*!
 * @brief enable/disable IPv6 address acquiring from Router Advertisement(stateless IP autoconfiguration)
 *
 */
extern INT32 c_net_ip_v6_auto(CHAR *ps_ni_name, BOOL b_enable, BOOL b_restart_if);
extern INT32 c_net_ip_v6_disable(const CHAR *ps_ni_name);

/*!
 * @brief enable/disable DHCPv6 to require IPv6 address (stateful autoconfiguration)
 *
 */
extern INT32 c_net_ip_v6_dhcp(CHAR *ps_ni_name, BOOL b_enable, INT32 dhcp_type);

/*!
 * @brief enable/disable auto DNS)
 *
 */
extern INT32 c_net_dns_v6_auto(CHAR *ps_ni_name, BOOL b_enable);

/*!
 * @brief ping utility, user may use this API to verify remote host is online or not.
 * @param in ps_ip     - dot format IPv4 address string, ex "192.168.1.1"
 * @param in i2_len    - payload size (send data size)
 * @param in i2_wait   - maximum wait time (in seconds)
 * @param in notify_fn - notify callback
 */
extern VOID c_net_ping_v6(CHAR * ps_ip,
                          INT32  i4_len,
                          INT16  i2_wait,
                          VOID (*notify_fn) (INT16 i2_rsp_time));

/*!
 * @brief obtain IPv6/prefix, gateway, dns etc. information
 * @param in ps_ni_name            - device name, e.g. "eth0"
 * @param out pt_info              - information structure, including ip/prefix, gw & dns; the space need be allocated by caller
 * @return error code
 * @retval = 0  - on success 
 * @retval = -1 - an error occurs
 */
extern INT32 c_net_get_v6_info(const CHAR* ps_ni_name, MT_IPV6_INFO_T* pt_info);

extern INT32 c_net_is_network_connect_v6(CHAR *ps_url);

extern INT32 c_net_network_reg_nfy_ipv6(x_network_status_nfy pf_nfy, UINT32 ui4_tag, NET_IPV6_MODE_T e_mode);

/*!
 * @brief network address translation for IPv6
 * @param in hostname            - host (URL) name, e.g. "www.xxx.com"
 * @param out size               - returned number of IP addresses (i.e. the number of the char* in return char**)
 * @return IP addresses
 * @retval != NULL - on success 
 * @retval = NULL  - an error occurs
 * @note please call free() with returned char**
 * @example
 *      char** ips = c_net_dns_v6_lookup("xxx.com", NULL);
 *      free(ips);
 */
extern CHAR** c_net_dns_v6_lookup(const CHAR* hostname, INT32* size);

/*!
 * @brief resolving url and make a connection (IPv6)
 * @param in url            - host (URL) name, e.g. "www.xxx.com" or "fe80::" or "fe80::%64" 
 * @param in port           - port (remote host)
 * @return return the error code
 * @retval  = 0     - on success
 * @retval != 0     - on error
 */
extern INT32 c_net_tcp_connect_test_v6(const CHAR *url, int port);

/*!
 * @brief set /etc/gai.conf
 * @param in enable         - if enable is true, prefer configuration; else non-prefer.
 * @return return the error code
 * @retval  = 0     - on success
 * @retval != 0     - on error
 */
extern INT32 c_net_set_prefer_v6(BOOL enable);
extern INT32 c_net_ni_rmv6config_all(char* dev);


/*!
 * @brief network address translation for IPv4
 * @param in hostname            - host (URL) name, e.g. "www.xxx.com"
 * @param out size               - returned number of IP addresses (i.e. the number of the char* in return char**)
 * @return IP addresses
 * @retval != NULL - on success 
 * @retval = NULL  - an error occurs
 * @note please call free() with returned char**
 * @example
 *      char** ips = c_net_dns_v4_lookup("xxx.com", NULL);
 *      free(ips);
 */
extern CHAR** c_net_dns_v4_lookup(const CHAR* hostname, INT32* size);

/*!
 * @brief resolving url and make a connection (IPv4)
 * @param in url            - host (URL) name, e.g. "www.xxx.com" or "192.168.100.1"
 * @param in port           - port (remote host)
 * @return return the error code
 * @retval  = 0     - on success
 * @retval != 0     - on error
 */
extern INT32 c_net_tcp_connect_test_v4(const CHAR *url, int port);
/*!
 * @brief notify the netwrok is ready
 * @param in url            - unused
 * @return return the error code
 * @retval  = 0     - on success
 * @retval != 0     - on error
 */
extern INT32 c_net_network_ready (VOID *pv_arg);
/*!
 * @brief send the dummy event in behalf of  network interface
 * @param psz_name   the interface name
  * @param e_ev   the event
 * @return return the error code
 * @retval  = 0     - on success
 * @retval != 0     - on error
 */
extern INT32 c_net_ni_send_dumy_evt(const CHAR *psz_name,NI_DRV_EV_T e_ev);
#endif

/*! @} */
