/**
 * @brief Starts a data call using the profile number provided
 *
 * The function uses parameters provided from @a ds_client_open_call_type
 * call result.
 *
 * @param[in] client_handle Client handle
 * @param[in] profile_index Profile index
 * @param[in] pdp_type      PDP type
 *
 * @return Operation result
 * @retval E_DS_CLIENT_SUCCESS    On success.
 * @retval E_DS_CLIENT_FAILURE... On error.
 */
static ds_client_status_enum_type ds_client_start_call
(
  dsClientHandleType client_handle,
  int profile_index,
  int pdp_type
)
{
    ds_client_status_enum_type ret = E_DS_CLIENT_FAILURE_GENERAL;
    dsi_call_param_value_t param_info;
    dsi_hndl_t dsi_handle;
    ds_client_session_data *ds_global_data = (ds_client_session_data *)client_handle;
    LOC_LOGD("%s:%d]:Enter\n", __func__, __LINE__);
    if(ds_global_data == NULL) {
        LOC_LOGE("%s:%d]: Null callback parameter\n", __func__, __LINE__);
        goto err;
    }
    dsi_handle = ds_global_data->dsi_net_handle;
    //Set profile index as call parameter
    param_info.buf_val = NULL;
    param_info.num_val = profile_index;
    dsi_set_data_call_param(dsi_handle,
                            DSI_CALL_INFO_UMTS_PROFILE_IDX,
                            &param_info);

    //Set IP Version as call parameter
    param_info.buf_val = NULL;
    param_info.num_val = pdp_type;
    dsi_set_data_call_param(dsi_handle,
                            DSI_CALL_INFO_IP_VERSION,
                            &param_info);
    LOC_LOGD("%s:%d]: Starting emergency call with profile index %d; pdp_type:%d\n",
             __func__, __LINE__, profile_index, pdp_type);
    if(dsi_start_data_call(dsi_handle) == DSI_SUCCESS) {
        LOC_LOGD("%s:%d]: Sent request to start data call\n",
                 __func__, __LINE__);
        ret = E_DS_CLIENT_SUCCESS;
    }
    else {
        LOC_LOGE("%s:%d]: Could not send req to start data call \n", __func__, __LINE__);
        ret = E_DS_CLIENT_FAILURE_GENERAL;
        goto err;
    }

err:
    LOC_LOGD("%s:%d]:Exit\n", __func__, __LINE__);
    return ret;

}
int test_1_execute(dsi_test_obj_t * obj)
{
  dsi_hndl_t hndl;

  DSI_TEST_FUNC_ENTRY;

  do
  {
    dsi_inited = TRUE;
    /* get hndl */
    hndl = dsi_get_data_srvc_hndl(dsi_test_1_cb, (void *)obj);
    if (NULL == hndl)
    {
      printf("couldnt' get hndl \n");
      break;
    }

    /* statt data call */
    dsi_start_data_call(hndl);

    /* generate SNI async rsp */
    dsi_test_sni_rsp(hndl, sni_wds_hndl);

    /* generate pkt srvc ind */
    dsi_test_pkt_data_connected(sni_wds_hndl, sni_dev_id);

    /* generate NET PLATFORM UP EV */
    dsi_test_platform_up(sni_dev_id);
        
    /* wait for cond variable */
    pthread_mutex_lock(&mutex);
    pthread_cond_wait(&cond, &mutex);
    if (test_cb_event != DSI_EVT_NET_IS_CONN)
    {
      DSI_TEST_ERR("rcvd evt [%d] instead of NET_IS_CONN", test_cb_event);
      break;
    }
    pthread_mutex_unlock(&mutex);
    DSI_TEST_REPORT_LOG("%s","verified NET_IS_CONN rcvd");

    /* modem oos */
    qmi_sys_event_info_type sys_event_info;
    dsi_qmi_sys_cb(QMI_SYS_EVENT_MODEM_OUT_OF_SERVICE_IND,
                   &sys_event_info,
                   NULL);


    /* wait for cond variable */
    pthread_mutex_lock(&mutex);
    pthread_cond_wait(&cond, &mutex);
    if (test_cb_event != DSI_EVT_NET_NO_NET)
    {
      DSI_TEST_ERR("rcvd evt [%d] instead of NET_NO_NET", test_cb_event);
      break;
    }
    pthread_mutex_unlock(&mutex);
    
    DSI_TEST_REPORT_LOG("%s","verified NET_NO_NET rcvd in modem oos");

    /* get hndl */
    hndl = dsi_get_data_srvc_hndl(dsi_test_1_cb, (void *)obj);
    if (NULL != hndl)
    {
      DSI_TEST_ERR("able to get [%d] hndl when modem oos", hndl);
      break;
    }
    else
    {
      DSI_TEST_REPORT_LOG("%s","verified can't get hndl when modem oos");
    }    

    /* modem is */
    dsi_qmi_sys_cb(QMI_SYS_EVENT_MODEM_IN_SERVICE_IND,
                   &sys_event_info,
                   NULL);

    /* let dsi_netctrl lib be re-initialized again */
    sleep(1);

    /* get hndl */
    hndl = dsi_get_data_srvc_hndl(dsi_test_1_cb, (void *)obj);
    if (NULL == hndl)
    {
      DSI_TEST_ERR("%s","couldnt' get hndl \n");
      break;
    }

    /* statt data call */
    dsi_start_data_call(hndl);

    /* generate SNI async rsp */
    dsi_test_sni_rsp(hndl, sni_wds_hndl);

    /* generate pkt srvc ind */
    dsi_test_pkt_data_connected(sni_wds_hndl, sni_dev_id);

    /* generate NET PLATFORM UP EV */
    dsi_test_platform_up(sni_dev_id);
        
    /* wait for cond variable */
    pthread_mutex_lock(&mutex);
    pthread_cond_wait(&cond, &mutex);
    if (test_cb_event != DSI_EVT_NET_IS_CONN)
    {
      DSI_TEST_ERR("rcvd evt [%d] instead of NET_IS_CONN", test_cb_event);
      break;
    }
    pthread_mutex_unlock(&mutex);
    DSI_TEST_REPORT_LOG("%s","verified NET_IS_CONN rcvd after modem is");

    /* generate NET PLATFORM DOWN EV */
    dsi_test_platform_down(sni_dev_id);

    /* wait for cond variable */
    pthread_mutex_lock(&mutex);
    pthread_cond_wait(&cond, &mutex);
    if (test_cb_event != DSI_EVT_NET_NO_NET)
    {
      DSI_TEST_ERR("rcvd evt [%d] instead of NET_NO_NET", test_cb_event);
      break;
    }
    pthread_mutex_unlock(&mutex);
    DSI_TEST_REPORT_LOG("%s","verified NET_NO_NET rcvd after test posted platform down");

    /* if condition is signalled, test passes */
    DSI_TEST_REPORT_LOG("[%s] PASS", obj->name);
    DSI_TEST_FUNC_EXIT;
    return;
  } while (0);

  DSI_TEST_REPORT_LOG("[%s] FAIL", obj->name);
  DSI_TEST_FUNC_EXIT;
}