#include <stdbool.h>
#include <unistd.h>
#include <dlfcn.h>
#include <time.h>
#include "gsw_nw_interface.h"
#include "gsw_log_interface.h"


#define MBTK_BUFF_TEMP_SIZE_32  32
#define MBTK_ERR_OK             0
#define MBTK_ERR_FAIL             -1
#define GSW_SIM_ICCID_LENGTH 15+1 
#define GSW_SIM_IMSI_LENGTH 15+1 
#define GSW_SIM_MSISDN_LENGTH 15+1

//mbtk include
typedef unsigned int uint32;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef void (*mbtk_info_callback_func)(const void* data, int data_len);
typedef struct
{
    int client_fd;
    pthread_t read_thread_id;
    int exit_fd[2];
    bool is_waitting;
    pthread_cond_t cond;
    pthread_mutex_t mutex;

    pthread_mutex_t send_mutex;

    // Temp response data.
    uint16 info_err;
    uint16 data_len;
    void *data;

    //mbtk wyq for server_ready_status add start
    char server_ready_status;
    //mbtk wyq for server_ready_status add end

    mbtk_info_callback_func net_state_cb;
    mbtk_info_callback_func call_state_cb;
    mbtk_info_callback_func sms_state_cb;
    mbtk_info_callback_func radio_state_cb;
    mbtk_info_callback_func sim_state_cb;
    mbtk_info_callback_func pdp_state_cb;
    //add signal by xr
    mbtk_info_callback_func signal_state_cb;
} mbtk_info_handle_t;

typedef enum {
    MBTK_SIM_ABSENT = 0,
    MBTK_SIM_NOT_READY = 1,
    MBTK_SIM_READY = 2,
    MBTK_SIM_PIN = 3,
    MBTK_SIM_PUK = 4,
    MBTK_SIM_NETWORK_PERSONALIZATION = 5
} mbtk_sim_state_enum;

typedef enum
{
    MBTK_DEV_MODEM_MIN_FUN,                                   //Modem 最小功能
    MBTK_DEV_MODEM_FULL_FUN,                                  //Modem 全功能
    MBTK_DEV_MODEM_DISABLE_RECEIVE_RF_CIRCUITS = 3,           //Modem 禁用射频接收电路
    MBTK_DEV_MODEM_DISABLE_TRANSMIT_AND_RECEIVE_RF_CIRCUITS,  //Modem禁用射频发射和接收电路
    MBTK_DEV_MODEM_DISABLE_SIM,                               //Modem 禁用(U)SIM 卡
    MBTK_DEV_MODEM_TURN_OFF_FULL_SECONDARY_RECEIVE,           //Modem 完全禁用辅助接收
}MBTK_DEV_MODEM_FUNCTION;

typedef struct
{
    MBTK_DEV_MODEM_FUNCTION fun;
    int rst;
} mbtk_modem_info_t;

//api

static mbtk_info_handle_t* (*mbtk_info_handle_get)(void);
#define lib_mbtk_path "/lib/libmbtk_lib.so"

static int sim_init_flag = 0;
mbtk_info_handle_t*       sim_info_handle = NULL;
static int (*mbtk_info_handle_free)(mbtk_info_handle_t** handle);
int (*mbtk_sim_state_get)(mbtk_info_handle_t* handle, mbtk_sim_state_enum *sim_state);
int (*mbtk_imsi_get)(mbtk_info_handle_t* handle, void *imsi);
int (*mbtk_iccid_get)(mbtk_info_handle_t* handle, void *iccid);
int (*mbtk_phone_number_get)(mbtk_info_handle_t* handle, void *phone_number);
int (*mbtk_set_modem_fun)(mbtk_info_handle_t* handle, mbtk_modem_info_t *info);
int (*mbtk_sim_power_set)(int power);


#define GSW_SIM "[HAL][GSW_SIM]"

static void *dlHandle_mbtk;


static int gsw_sim_api_import()
{
    dlHandle_mbtk = dlopen(lib_mbtk_path, RTLD_NOW);
    if (dlHandle_mbtk == NULL) 
    {
        return GSW_HAL_NORMAL_FAIL;
    }

    mbtk_info_handle_get = (mbtk_info_handle_t* (*)(void))dlsym(dlHandle_mbtk, "mbtk_info_handle_get");
    if (mbtk_info_handle_get == NULL) 
    {
        LOGE(GSW_SIM,"mbtk_info_handle_get dlsym fail\n");
        return GSW_HAL_NORMAL_FAIL;
    }

    mbtk_info_handle_free = (int (*)(mbtk_info_handle_t** handle))dlsym(dlHandle_mbtk, "mbtk_info_handle_free");
    if (mbtk_info_handle_free == NULL) 
    {
        LOGE(GSW_SIM,"mbtk_info_handle_free dlsym fail\n");
        return GSW_HAL_NORMAL_FAIL;
    }

    mbtk_imsi_get = (int (*)(mbtk_info_handle_t* handle, void *imsi))dlsym(dlHandle_mbtk, "mbtk_imsi_get");
    if (mbtk_imsi_get == NULL) 
    {
        LOGE(GSW_SIM,"mbtk_imsi_get dlsym fail\n");
        return GSW_HAL_NORMAL_FAIL;
    }

    mbtk_iccid_get = (int (*)(mbtk_info_handle_t* handle, void *iccid))dlsym(dlHandle_mbtk, "mbtk_iccid_get");
    if (mbtk_iccid_get == NULL) 
    {
        LOGE(GSW_SIM,"mbtk_iccid_get dlsym fail\n");
        return GSW_HAL_NORMAL_FAIL;
    }

    mbtk_phone_number_get = (int (*)(mbtk_info_handle_t* handle, void *phone_number))dlsym(dlHandle_mbtk, "mbtk_phone_number_get");
    if (mbtk_phone_number_get == NULL) 
    {
        LOGE(GSW_SIM,"mbtk_phone_number_get dlsym fail\n");
        return GSW_HAL_NORMAL_FAIL;
    }

   
    mbtk_sim_state_get = (int (*)(mbtk_info_handle_t* handle, mbtk_sim_state_enum *sim_state))dlsym(dlHandle_mbtk, "mbtk_sim_state_get");
    if (mbtk_sim_state_get == NULL) 
    {
        LOGE(GSW_SIM,"mbtk_sim_state_get dlsym fail\n");
        return GSW_HAL_NORMAL_FAIL;
    }

    mbtk_set_modem_fun = (int (*)(mbtk_info_handle_t* handle, mbtk_modem_info_t *info))dlsym(dlHandle_mbtk, "mbtk_set_modem_fun");
    if (mbtk_set_modem_fun == NULL) 
    {
        LOGE(GSW_SIM,"mbtk_set_modem_fun dlsym fail\n");
        return GSW_HAL_NORMAL_FAIL;
    }

    mbtk_sim_power_set = (int (*)(int power))dlsym(dlHandle_mbtk, "mbtk_sim_power_set");
    if (mbtk_sim_power_set == NULL)
    {
        LOGE(GSW_SIM,"mbtk_sim_power_set dlsym fail\n");
        return GSW_HAL_NORMAL_FAIL;
    }

    LOGD(GSW_SIM,"gsw_sim_api_import end\n");
    return GSW_HAL_SUCCESS;
}

/**
 * @brief sim sdk init
 * @param  [in] token usr id define by who use
 * @retval 0: success
 * @retval other: fail
 */
int gsw_sim_sdk_init(int32_t token)
{
    int ret = GSW_HAL_NORMAL_FAIL;

    if(sim_init_flag == 1 && sim_info_handle != NULL)
    {
        return GSW_HAL_SUCCESS;
    }

    ret = gsw_sim_api_import();
    if(ret != GSW_HAL_SUCCESS)
    {
        LOGE(GSW_SIM,"gsw_sim_import fail\n");
        return GSW_HAL_NORMAL_FAIL;
    }

    sim_info_handle = mbtk_info_handle_get();
    if(sim_info_handle == NULL)
    {
        LOGE(GSW_SIM,"mbtk_info_handle_get fail\n");
        return GSW_HAL_NORMAL_FAIL;
    }

    sim_init_flag = 1;
    return GSW_HAL_SUCCESS;
}


/**
 * @brief sim sdk deinit
 * @param 
 * @retval 0: success
 * @retval other: fail
 */
int gsw_sim_sdk_deinit(void)
{
    int ret = -1;

    if(sim_init_flag == 0 || sim_info_handle == NULL)
    {
        printf("sim sdk has been deinit\n");
        return GSW_HAL_NORMAL_FAIL;
    }

    ret = mbtk_info_handle_free(&sim_info_handle);
    if(ret != GSW_HAL_SUCCESS)
    {
        LOGE(GSW_SIM,"mbtk_info_handle_free fail\n");
        return GSW_HAL_NORMAL_FAIL;
    }

    sim_init_flag = 0;
    sim_info_handle = NULL;
    dlclose(dlHandle_mbtk);

    return GSW_HAL_SUCCESS;

}


/**
 * @brief get sim state
 * @param  [out] sim_state sim status as sim_status_e_type
 * @retval 0: success
 * @retval other: fail
 */
int gsw_get_sim_status(int *sim_state)
{
    printf("gsw_get_sim_status enter\n");
    int ret = -1;

    if(sim_init_flag == 0 || sim_info_handle == NULL)
    {
        printf("sim sdk has been deinit\n");
        return GSW_HAL_NORMAL_FAIL;
    }

    mbtk_sim_state_enum sim = MBTK_SIM_ABSENT;

    LOGD(GSW_SIM,"mbtk_get_sim_status start\n");
    ret = mbtk_sim_state_get(sim_info_handle, &sim);
    if(ret)
    {
        LOGE(GSW_SIM,"[gsw_get_sim_status] mbtk_sim_state_get fail [err = %d].", ret);
        return GSW_HAL_NORMAL_FAIL;
    }

    else
    {
        LOGD(GSW_SIM,"[gsw_get_sim_status] sim = %d\n", sim);
        switch (sim)
        {
            case MBTK_SIM_ABSENT:
            {
                *sim_state = SIM_STATUS_ABSENT;
                break;
            }
            case MBTK_SIM_NOT_READY:
            {
                *sim_state = SIM_STATUS_ERROR;// not SIM_STATUS_PRESENT, changed for gsw requirement, hq at 250606
                break;
            }
                
            case MBTK_SIM_READY:
            {
                *sim_state = SIM_STATUS_PRESENT;// not SIM_STATUS_READY, changed for gsw requirement, hq at 250606
                break;
            }
                
            case MBTK_SIM_PIN:
            {
                *sim_state = SIM_STATUS_PIN;
                break;
            }

            case MBTK_SIM_PUK:
            {
                break;
            }

            case MBTK_SIM_NETWORK_PERSONALIZATION:
            {
                break;
            }
        
        }
    }

    return GSW_HAL_SUCCESS;
}

/**
 * @brief get iccid function
 * @param  [in] len iccid length,max is 20
 * @param  [out] iccid return iccid from this func
 * @retval 0: success
 * @retval other: fail
 */
int gsw_get_sim_iccid(int len, char *iccid)
{
    int ret = -1;

    if(sim_init_flag == 0 || sim_info_handle == NULL)
    {
        printf("sim sdk has been deinit\n");
        return GSW_HAL_NORMAL_FAIL;
    }

    if(iccid == NULL)
    {
        LOGE(GSW_SIM,"iccid is NULL.");
        return GSW_HAL_ARG_INVALID;
    }

    if(len < GSW_SIM_ICCID_LENGTH)
    {
        LOGE(GSW_SIM,"iccid len is too short,len = %d\n", len);
        return GSW_HAL_NORMAL_FAIL;
    }

    ret = mbtk_iccid_get(sim_info_handle, (void *)iccid);
    if(ret != MBTK_ERR_OK)
    {
        LOGE(GSW_SIM,"[gsw_sim] mbtk_iccid_get fail [err = %d].", ret);
        return GSW_HAL_NORMAL_FAIL;
    }

    return GSW_HAL_SUCCESS;
}

/**
 * @brief get imsi function
 * @param  [in] len imsi length,max is 20
 * @param  [out] iccid return imsi from this func
 * @retval 0: success
 * @retval other: fail
 */
int gsw_get_sim_imsi(int len, char *imsi)
{
    int ret = -1;

    if(sim_init_flag == 0 || sim_info_handle == NULL)
    {
        printf("sim sdk has been deinit\n");
        return GSW_HAL_NORMAL_FAIL;
    }

    if(imsi == NULL)
    {
        LOGE(GSW_SIM,"imsi is NULL.");
        return GSW_HAL_ARG_INVALID;
    }

    if(len < GSW_SIM_IMSI_LENGTH)
    {
        LOGE(GSW_SIM,"imsi len is too short,len = %d\n", len);
        return GSW_HAL_NORMAL_FAIL;
    }

    ret = mbtk_imsi_get(sim_info_handle, (void *)imsi);
    if(ret != MBTK_ERR_OK)
    {
        LOGE(GSW_SIM,"[gsw_sim] mbtk_imsi_get fail [err = %d].", ret);
        return GSW_HAL_NORMAL_FAIL;
    }

    return GSW_HAL_SUCCESS;
}

/**
 * @brief get sim msisdn function
 * @param  [in] len msisdn length,max is 20
 * @param  [out] msisdn msisdn length,max is 20
 * @retval 0: success
 * @retval other: fail
 */
int gsw_get_sim_msisdn(int len, char *msisdn)
{
    int ret = -1;

    if(sim_init_flag == 0 || sim_info_handle == NULL)
    {
        printf("sim sdk has been deinit\n");
        return GSW_HAL_NORMAL_FAIL;
    }

    if(msisdn == NULL)
    {
        printf("msisdn is NULL.");
        return GSW_HAL_ARG_INVALID;
    }

    if(len < GSW_SIM_MSISDN_LENGTH)
    {
        printf("msisdn len is too short,len = %d\n", len);
        return GSW_HAL_NORMAL_FAIL;
    }

    ret = mbtk_phone_number_get(sim_info_handle, (void *)msisdn);
    if(ret != MBTK_ERR_OK)
    {
        LOGE(GSW_SIM,"[gsw_sim] mbtk_phone_number_get fail [err = %d].", ret);
        return GSW_HAL_NORMAL_FAIL;
    }

    return GSW_HAL_SUCCESS;
}

/**
 * @brief set sim power down
 * @param  
 * @retval 0: success
 * @retval other: fail
 */
int gsw_set_sim_power_down(void)
{
    int ret = -1;
    if(sim_init_flag == 0 || sim_info_handle == NULL)
    {
        printf("sim sdk has been deinit\n");
        return GSW_HAL_NORMAL_FAIL;
    }

    mbtk_modem_info_t info;
    info.fun = MBTK_DEV_MODEM_DISABLE_SIM;
    info.rst = 0;

    ret = mbtk_set_modem_fun(sim_info_handle, &info);
    if(ret)
    {
        LOGE(GSW_SIM,"mbtk_set_modem_fun() fail [err = %d].", ret);
        return GSW_HAL_NORMAL_FAIL;
    }

    return GSW_HAL_SUCCESS;
}



/**
 * @brief set sim power up
 * @param 
 * @retval 0: success
 * @retval other: fail
 */
int gsw_set_sim_power_up(void)
{
    int ret = -1;
    if(sim_init_flag == 0 || sim_info_handle == NULL)
    {
        printf("sim sdk has been deinit\n");
        return GSW_HAL_NORMAL_FAIL;
    }

    mbtk_modem_info_t info;
    info.fun = MBTK_DEV_MODEM_FULL_FUN;
    info.rst = 0;

    ret = mbtk_set_modem_fun(sim_info_handle, &info);
    if(ret)
    {
        LOGE(GSW_SIM,"mbtk_set_modem_fun() fail [err = %d].", ret);
        return GSW_HAL_NORMAL_FAIL;
    }
    
    return GSW_HAL_SUCCESS;
}
