/* 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_dlm_net.h 
 *  $RCSfile: $
 *  $Revision: #1 $
 *  $Date: 2015/05/29 $
 *  $Author: brianpc.huang $ 
 *  
 *  @par Description:
 *         This header file contains download firmware c_api
 *         definitions, which are exported.
 *         
 */
/*----------------------------------------------------------------------------*/

#ifndef __C_DLM_NET_H__
#define __C_DLM_NET_H__

/*----------------------------------------------------------------------------*/
/*! @addtogroup groupMW_INET_DLM_NET
 *  @{
 */
/*----------------------------------------------------------------------------*/

#include "u_dlm_net.h"

/*------------------------------------------------------------------*/
/*! @brief This function is called by application when it wants to start download via network
 *  @param [out] ph_dlm_net  -a struct point for download firmware
 *  @return Return the error code
 *  @retval     DLM_NETR_OK  -successful
 *  @retval     DLM_NETR_OUT_OF_MEMORY  -out of memory
 *  @retval     DLM_NETR_SESSION_ERROR  -new http session for authenticate error
 *  @retval     DLM_NETR_SET_OPT_ERROR  -set http session option error
 */
/*------------------------------------------------------------------*/
extern INT32 c_dlm_net_init(UINT32 *ph_dlm_net);
/*------------------------------------------------------------------*/
/*! @brief This function is caled by application to download firmware note by range
 *  @param [in] h_dlm_net       -a struct point for download firmware which init by c_dlm_net_init
 *  @param [in] ui4_start         -offset of current firmware which want to download
 *  @param [in] ui4_size           -size of current firmware which want to download and size of ps_buf
 *  @param [out] ps_buf     -buffer that save download firmware allocated by application
 *  @param [in] pf_dl_cb          -download callback function, define by application
 *  @param [in] pf_progress     -progress callback function, define by application
 *  @return Return the error code
 *  @retval     DLM_NETR_OK  -successful
 *  @retval     DLM_NETR_INVALID_ARGUMENT  -argument is invalid
 *  @retval     DLM_NETR_DOWNLOAD_ERROR  -start download error
 *  @retval     DLM_NETR_SET_OPT_ERROR  -set http option error
 */
/*------------------------------------------------------------------*/
extern INT32 c_dlm_net_download(UINT32 h_dlm_net, 
                                      UINT32 ui4_start, 
                                      UINT32 ui4_size, 
                                      CHAR *ps_buf, 
                                      x_dlm_net_dl_async_cb pf_dl_cb, 
                                      x_dlm_net_progress_cb pf_progress_nfy);
/*------------------------------------------------------------------*/
/*! @brief This function is called by application when it wants to cancel download process
 *  @param [in] h_dlm_net   -a struct point for download firmware which init by c_dlm_net_init
 *  @return Return the error code
 *  @retval     DLM_NETR_OK  -successful
 *  @retval     DLM_NETR_INVALID_ARGUMENT  -argument is invalid
 *  @retval     DLM_NETR_SET_OPT_ERROR  -set http async session abort error
 */
/*------------------------------------------------------------------*/
extern INT32 c_dlm_net_cancel(UINT32 h_dlm_net);
/*------------------------------------------------------------------*/
/*! @brief This function is called by application when it wants to release resource
 *  @param [in] h_dlm_net   -a struct point for download firmware which init by c_dlm_net_init
 *  @return Return the error code
 *  @retval      DLM_NETR_OK  -successful
 */
/*------------------------------------------------------------------*/
extern INT32 c_dlm_net_deinit(UINT32 h_dlm_net);
/*------------------------------------------------------------------*/
/*! @brief This function is called by application when it wants authenticate with server
 *  @param [in] h_dlm_net       -a struct point for download firmware which init by c_dlm_net_init
 *  @param [in] ps_url         -url with information which wants to send to server
 *  @param [in] pf_auth_cb          -authenticate callback function, define by application
 *  @param [in] pf_progress     -progress callback function, define by application
 *  @return Return the error code
 *  @retval     DLM_NETR_OK  -successful
 *  @retval     DLM_NETR_INVALID_ARGUMENT  -argument is invalid
 *  @retval     DLM_NETR_AUTHENTICATE_ERROR  -start authenticate error
 *  @retval     DLM_NETR_OUT_OF_MEMORY  -out of memory
 *  @retval     DLM_NETR_SET_OPT_ERROR  -set http option error
 */
/*------------------------------------------------------------------*/
extern INT32 c_dlm_net_authenticate(UINT32 h_dlm_net,
                                        CHAR *ps_url,
                                        x_dlm_net_auth_async_cb pf_auth_cb,
                                        x_dlm_net_progress_cb pf_progress_nfy);
/*------------------------------------------------------------------*/
/*! @brief This function is caled by application when it get download url and want to connect with server
 *  @param [in] h_dlm_net       -a struct point for download firmware which init by c_dlm_net_init
 *  @param [in] ps_url     -url of firmware saved on server
 *  @param [out] pui8_len     -firmware file total size, if error will return DLM_NET_UNKNOW_SIZE
 *  @return Return the error code
 *  @retval     DLM_NETR_OK  -successful
 *  @retval     DLM_NETR_INVALID_ARGUMENT  -argument is invalid
 *  @retval     DLM_NETR_SESSION_ERROR  -http streaming open error
 *  @retval     DLM_NETR_SET_OPT_ERROR  -set http option error
 */
/*------------------------------------------------------------------*/
extern INT32 c_dlm_net_set_download_url(UINT32 h_dlm_net,
                                        CHAR *ps_url,
                                        UINT64 *pui8_len);
/*------------------------------------------------------------------*/
/*! @brief This function is caled by application when it wants to set certificate path
 *  @param [in] h_dlm_net       -a struct point for download firmware which init by c_dlm_net_init
 *  @param [in] ps_ca_path     -path of certificate for server
 *  @return Return the error code
 *  @retval     DLM_NETR_OK  -successful
 *  @retval     DLM_NETR_INVALID_ARGUMENT  -argument is invalid
 *  @retval     DLM_NETR_OUT_OF_MEMORY  -out of memory
 */
/*------------------------------------------------------------------*/
extern INT32 c_dlm_net_set_ca_path(UINT32 h_dlm_net,
                                        CHAR *ps_ca_path);

/*----------------------------------------------------------------------------*/
/*! @} */
/*----------------------------------------------------------------------------*/

#endif /* __C_DLM_NET_H__ */

