int qmi_ip_wds_init(qmi_ip_conf_t * conf, SSL* s, qmi_client_qmux_instance_type rmnet_instance)
{
  qmi_service_info qmi_svc_info;
  int ret_val;
  qmi_client_error_type err;
  qmi_idl_service_object_type wds_service_object;
  wds_indication_register_req_msg_v01 ind_req;
  wds_indication_register_resp_msg_v01 ind_resp;
/*- - - - - - - - - --  - - - - - - -- - - - - - - - - - - - - - - - - - - - */
  if (s == NULL || conf == NULL)
    return -1;
  ssl = s;

  if ((conf->qmi_ip_v4_wds_handle != 0) && (conf->qmi_ip_v6_wds_handle != 0)){
    LOG_MSG_ERROR("Handles already populated",0,0,0);
    return QMI_IP_SUCCESS;
  }

  /*------------------------------------------------------------------
  Get the service object, wait for the service and get the information
  about the service and then get an handle for the service.
  -------------------------------------------------------------------*/
  wds_service_object = wds_get_service_object_v01();

  if(!wds_service_object)
  {
    LOG_MSG_ERROR("qmi_ip wds get service object failed",0,0,0);
    return QMI_IP_ERROR;
  }

  memset(&qmi_svc_info,0,sizeof(qmi_service_info ));

  if(!qmi_ip_wait_for_srv_then_get_info(wds_service_object,
                                      &qmi_svc_info,
                                        rmnet_instance))
  {
    LOG_MSG_ERROR("Error getting info for QMI_IP service",0,0,0);
    return QMI_IP_ERROR;
  }
  /*----------------------------------------------------------------
  Get handle for IPv4
  ------------------------------------------------------------------*/
  ret_val = qmi_client_init(&qmi_svc_info,
                            wds_service_object,
                            (void *) qmi_ip_wds_ind_cb,
                            NULL,
                            NULL,
                            &(conf->qmi_ip_v4_wds_handle));

  if(ret_val != QMI_NO_ERR)
  {
    LOG_MSG_ERROR("Error while trying to initialize client %d", ret_val,0,0);
    return QMI_IP_ERROR;
  }
  else
  {
    LOG_MSG_INFO1("Successfully allocated client init WDS service for v4, handle %d",
                  conf->qmi_ip_v4_wds_handle,0,0);
  }

  if (rmnet_instance != QMI_CLIENT_QMUX_RMNET_INSTANCE_8)
  {
    memset(&ind_req, 0, sizeof(wds_indication_register_req_msg_v01));
    memset(&ind_resp, 0, sizeof(wds_indication_register_resp_msg_v01));
    ind_req.report_embms_tmgi_list_valid = 1;
    ind_req.report_embms_tmgi_list = 1;
    ret_val = qmi_client_send_msg_sync(conf->qmi_ip_v4_wds_handle,
                                       QMI_WDS_INDICATION_REGISTER_REQ_V01,
                                       (void*)&ind_req,
                                       sizeof(wds_indication_register_req_msg_v01),
                                       (void*)&ind_resp,
                                       sizeof(wds_indication_register_resp_msg_v01),
                                       QMI_TIMEOUT);

    if((ret_val != QMI_NO_ERR) || (ind_resp.resp.result != QMI_NO_ERR))
    {
      LOG_MSG_ERROR("Error while trying send message: %d %d", ret_val,
                    ind_resp.resp.result,0);
      return QMI_IP_ERROR;
    }
  }

  /*----------------------------------------------------------------------
  Get handle for IPV6
  -----------------------------------------------------------------------*/
  ret_val = qmi_client_init(&qmi_svc_info,
                            wds_service_object,
                            (void *) qmi_ip_wds_ind_cb,
                            NULL,
                            NULL,
                            &(conf->qmi_ip_v6_wds_handle));
  if(ret_val != QMI_NO_ERR)
  {
    LOG_MSG_ERROR("Error while trying to initialize client ",0,0,0);
    return QMI_IP_ERROR;
  }
  else
  {
    LOG_MSG_INFO1("Successfully allocated client for v6, handle %d",
                  conf->qmi_ip_v6_wds_handle,0,0);
  }

  return QMI_IP_SUCCESS;
}
/*This function is called to obtain a handle to the QMI WDS service*/
static ds_client_status_enum_type
ds_client_qmi_ctrl_point_init(qmi_client_type *p_wds_qmi_client)
{
    qmi_client_type wds_qmi_client, notifier = NULL;
    ds_client_status_enum_type status = E_DS_CLIENT_SUCCESS;
    qmi_service_info *p_service_info = NULL;
    uint32_t num_services = 0, num_entries = 0;
    qmi_client_error_type ret = QMI_NO_ERR;
    unsigned char no_signal = 0;
    qmi_client_os_params os_params;
    int timeout = 0;

    LOC_LOGD("%s:%d]:Enter\n", __func__, __LINE__);

    //Get service object for QMI_WDS service
    qmi_idl_service_object_type ds_client_service_object =
        wds_get_service_object_v01();
    if(ds_client_service_object == NULL) {
        LOC_LOGE("%s:%d]: wds_get_service_object_v01 failed\n" ,
                    __func__, __LINE__);
        status  = E_DS_CLIENT_FAILURE_INTERNAL;
        goto err;
    }

    //get service addressing information
    ret = qmi_client_get_service_list(ds_client_service_object, NULL, NULL,
                                      &num_services);
    LOC_LOGD("%s:%d]: qmi_client_get_service_list() first try ret %d, "
                   "num_services %d]\n", __func__, __LINE__, ret, num_services);
    if(ret != QMI_NO_ERR) {
        //Register for service notification
        ret = qmi_client_notifier_init(ds_client_service_object, &os_params, &notifier);
        if (ret != QMI_NO_ERR) {
            LOC_LOGE("%s:%d]: qmi_client_notifier_init failed %d\n",
                              __func__, __LINE__, ret);
            status = E_DS_CLIENT_FAILURE_INTERNAL;
            goto err;
        }

        do {
            QMI_CCI_OS_SIGNAL_CLEAR(&os_params);
            ret = qmi_client_get_service_list(ds_client_service_object, NULL,
                                              NULL, &num_services);
            if(ret != QMI_NO_ERR) {
                QMI_CCI_OS_SIGNAL_WAIT(&os_params, DS_CLIENT_SERVICE_TIMEOUT);
                no_signal = QMI_CCI_OS_SIGNAL_TIMED_OUT(&os_params);
                if(!no_signal)
                    ret = qmi_client_get_service_list(ds_client_service_object, NULL,
                                                      NULL, &num_services);
            }
            timeout += DS_CLIENT_SERVICE_TIMEOUT;
            LOC_LOGV("%s:%d]: qmi_client_get_service_list() returned ret: %d,"
                     "no_signal: %d, total timeout: %d\n", __func__, __LINE__,
                     ret, no_signal, timeout);
        } while( (timeout < DS_CLIENT_SERVICE_TIMEOUT_TOTAL) &&
                 no_signal &&
                 (ret != QMI_NO_ERR) );
    }

    //Handle failure cases
    if(num_services == 0 || ret != QMI_NO_ERR) {
        if(!no_signal) {
            LOC_LOGE("%s:%d]: qmi_client_get_service_list failed even though"
                     "service is up!  Error: %d \n", __func__, __LINE__, ret);
            status = E_DS_CLIENT_FAILURE_INTERNAL;
        }
        else {
            LOC_LOGE("%s:%d]: qmi_client_get_service_list failed after retries"
                     "Error: %d \n", __func__, __LINE__, ret);
            status = E_DS_CLIENT_FAILURE_TIMEOUT;
        }
        goto err;
    }

    LOC_LOGD("%s:%d]: qmi_client_get_service_list succeeded\n", __func__, __LINE__);

    //Success
    p_service_info = (qmi_service_info *)malloc(num_services * sizeof(qmi_service_info));
    if(p_service_info == NULL) {
        LOC_LOGE("%s:%d]: could not allocate memory for serviceInfo !!\n",
               __func__, __LINE__);
        status = E_DS_CLIENT_FAILURE_INTERNAL;
        goto err;
    }
    num_entries = num_services;

    //Populate service info
    ret = qmi_client_get_service_list(ds_client_service_object, p_service_info,
                                     &num_entries, &num_services);
    if(ret != QMI_NO_ERR) {
        LOC_LOGE("%s:%d]: qmi_client_get_service_list failed. ret: %d \n",
                 __func__, __LINE__, ret);
        status = E_DS_CLIENT_FAILURE_INTERNAL;
        goto err;
    }

    //Initialize wds_qmi_client
    LOC_LOGD("%s:%d]: Initializing WDS client with qmi_client_init\n", __func__,
             __LINE__);
    ret = qmi_client_init(&p_service_info[0], ds_client_service_object,
                          NULL, NULL, NULL, &wds_qmi_client);
    if(ret != QMI_NO_ERR) {
        LOC_LOGE("%s:%d]: qmi_client_init Error. ret: %d\n", __func__, __LINE__, ret);
        status = E_DS_CLIENT_FAILURE_INTERNAL;
        goto err;
    }
    LOC_LOGD("%s:%d]: WDS client initialized with qmi_client_init\n", __func__,
         __LINE__);

    //Store WDS QMI client handle in the parameter passed in
    *p_wds_qmi_client = wds_qmi_client;

    status = E_DS_CLIENT_SUCCESS;
    LOC_LOGD("%s:%d]: init success\n", __func__, __LINE__);

    if(notifier)
        qmi_client_release(notifier);

err:
    if(p_service_info)
        free(p_service_info);

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