#include <setjmp.h>
#include "data_connection.h"
-#include <network-cm-intf.h>
#include "debug_util.h"
+#include <net_connection.h>
int noti_resp_init(int *noti_pipe_fds);
int noti_resp_wait(int *noti_pipe_fds);
unsigned int g_ipaddr;
static int pdp_pipe_fds[2];
+static connection_h g_con = NULL;
+static connection_profile_h g_profile;
typedef enum {
DEACTIVATED,
DEACTIVATING
} pdp_status;
-char profile_name[NET_PROFILE_NAME_LEN_MAX + 1];
-
pdp_status act_level;
char *PdpStat[] = { "Deactivated", "Activating", "Activated", "Deactivating" };
static void pdp_proxy_conf()
{
- net_proxy_t proxy;
- int ret;
- ret = net_get_active_proxy(&proxy);
+ int ret = CONNECTION_ERROR_NOT_SUPPORTED;
+ char *address = NULL;
- if (ret == NET_ERR_NONE) {
- if (strncmp(proxy.proxy_addr, "0.0.0.0", 7)) {
+ ret = connection_get_proxy(g_con, CONNECTION_ADDRESS_FAMILY_IPV4, &address);
+ if (ret == CONNECTION_ERROR_NONE) {
+ if (strncmp(address, "0.0.0.0", 7)) {
char buf[100];
- snprintf(buf, sizeof(buf), "http://%s/", proxy.proxy_addr);
+ snprintf(buf, sizeof(buf), "http://%s/", address);
setenv("http_proxy", buf, 1);
} else {
unsetenv("http_proxy");
}
- } else {
- LOG_GPS(DBG_ERR, "Fail to get proxy\n");
}
+
}
-void pdp_evt_cb(net_event_info_t *event_cb, void *user_data)
+void pdp_evt_cb(connection_error_e result, void* user_data)
{
- switch (event_cb->Event) {
- case NET_EVENT_OPEN_RSP: {
- LOG_GPS(DBG_LOW, "event_cb->Error : [%d]\n", event_cb->Error);
- if (get_connection_status() != ACTIVATING) {
- LOG_GPS(DBG_LOW, "Not Activating status\n");
- } else if (event_cb->Error == NET_ERR_NONE || event_cb->Error == NET_ERR_ACTIVE_CONNECTION_EXISTS) {
- LOG_GPS(DBG_LOW, "Successful PDP Activation\n");
- net_profile_info_t *prof_info = NULL;
- net_dev_info_t *net_info = NULL;
-
- prof_info = (net_profile_info_t *) event_cb->Data;
- net_info = &(prof_info->ProfileInfo.Pdp.net_info);
-
- strncpy(profile_name, net_info->ProfileName, NET_PROFILE_NAME_LEN_MAX);
-
- set_connection_status(ACTIVATED);
- pdp_proxy_conf();
- noti_resp_noti(pdp_pipe_fds, TRUE);
- } else {
- LOG_GPS(DBG_ERR, " PDP Activation Failed - PDP Error[%d]\n", event_cb->Error);
- set_connection_status(DEACTIVATED);
- noti_resp_noti(pdp_pipe_fds, FALSE);
- }
- }
- break;
-
- case NET_EVENT_CLOSE_RSP:
- if (get_connection_status() != ACTIVATED && get_connection_status() != DEACTIVATING) {
- LOG_GPS(DBG_ERR, "Not Activated && Deactivating status\n");
- } else if (event_cb->Error == NET_ERR_NONE || event_cb->Error == NET_ERR_UNKNOWN) {
- LOG_GPS(DBG_LOW, "Successful PDP De-Activation\n");
- set_connection_status(DEACTIVATED);
- noti_resp_noti(pdp_pipe_fds, TRUE);
- } else {
- LOG_GPS(DBG_ERR, " PDP DeActivation Failed - PDP Error[%d]\n", event_cb->Error);
- noti_resp_noti(pdp_pipe_fds, FALSE);
- }
- break;
-
- case NET_EVENT_CLOSE_IND:
- if (get_connection_status() != ACTIVATED && get_connection_status() != DEACTIVATING) {
- LOG_GPS(DBG_ERR, "Not Activated && Deactivating status\n");
- } else if (event_cb->Error == NET_ERR_NONE || event_cb->Error == NET_ERR_UNKNOWN) {
- LOG_GPS(DBG_LOW, "Successful PDP De-Activation\n");
+ if (result == CONNECTION_ERROR_NONE) {
+ LOG_GPS(DBG_LOW, "Connected");
+ LOG_GPS(DBG_LOW, "Successful PDP Activation\n");
+ set_connection_status(ACTIVATED);
+ pdp_proxy_conf();
+ noti_resp_noti(pdp_pipe_fds, TRUE);
+ } else {
+ LOG_GPS(DBG_ERR, " PDP DeActivation Failed - PDP Error[%d]\n", result);
set_connection_status(DEACTIVATED);
- noti_resp_noti(pdp_pipe_fds, TRUE);
- } else {
- LOG_GPS(DBG_ERR, " PDP DeActivation Failed - PDP Error[%d]\n", event_cb->Error);
noti_resp_noti(pdp_pipe_fds, FALSE);
- }
- break;
- case NET_EVENT_OPEN_IND:
- break;
- default:
- break;
}
}
return FALSE;
}
- err = net_register_client((net_event_cb_t) pdp_evt_cb, NULL);
+ err = connection_create(&g_con);
- if (err == NET_ERR_NONE || err == NET_ERR_APP_ALREADY_REGISTERED) {
+ if (err == CONNECTION_ERROR_NONE ) {
LOG_GPS(DBG_LOW, "Client registration is succeed\n");
} else {
LOG_GPS(DBG_WARN, "Error in net_register_client [%d]\n", err);
+ return FALSE;
+ }
+
+
+ if (noti_resp_wait(pdp_pipe_fds) > 0) {
+ if (noti_resp_check(pdp_pipe_fds)) {
+ LOG_GPS(DBG_LOW, "PDP Activation Successful\n");
+
+ } else {
+ LOG_GPS(DBG_ERR, "PDP failed\n");
+ noti_resp_deinit(pdp_pipe_fds);
+ err = connection_destroy(g_con);
+ if (err == CONNECTION_ERROR_NONE)
+ LOG_GPS(DBG_LOW, "Client deregistered successfully\n");
+ else
+ LOG_GPS(DBG_ERR, "Error deregistering the client\n");
+
+ return FALSE;
+ }
+ } else {
+ LOG_GPS(DBG_ERR, "NO Pdp Act Response or Some error in select.\n");
noti_resp_deinit(pdp_pipe_fds);
+
+ err = connection_destroy(g_con);
+ if (err == CONNECTION_ERROR_NONE)
+ LOG_GPS(DBG_LOW, "Client deregistered successfully\n");
+ else
+ LOG_GPS(DBG_ERR, "Error deregistering the client\n");
+
return FALSE;
}
- set_connection_status(ACTIVATING);
- err = net_open_connection_with_preference(NET_SERVICE_INTERNET);
- if (err == NET_ERR_NONE) {
+ err = connection_get_default_cellular_service_profile(g_con,CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET,&g_profile);
+
+ if (err == CONNECTION_ERROR_NONE) {
LOG_GPS(DBG_LOW, "Sent PDP Activation.\n");
} else {
LOG_GPS(DBG_WARN, "Error in net_open_connection_with_preference() [%d]\n", err);
set_connection_status(DEACTIVATED);
- err = net_deregister_client();
- if (err == NET_ERR_NONE)
+ err = connection_destroy(g_con);
+ if (err == CONNECTION_ERROR_NONE)
LOG_GPS(DBG_LOW, "Client deregistered successfully\n");
else
LOG_GPS(DBG_ERR, "Error deregistering the client\n");
return FALSE;
}
- if (noti_resp_wait(pdp_pipe_fds) > 0) {
- if (noti_resp_check(pdp_pipe_fds)) {
- LOG_GPS(DBG_LOW, "PDP Activation Successful\n");
- noti_resp_deinit(pdp_pipe_fds);
- return TRUE;
- } else {
- LOG_GPS(DBG_ERR, "PDP failed\n");
- noti_resp_deinit(pdp_pipe_fds);
+ err = connection_open_profile(g_con,g_profile, pdp_evt_cb, NULL);
- err = net_deregister_client();
- if (err == NET_ERR_NONE)
- LOG_GPS(DBG_LOW, "Client deregistered successfully\n");
- else
- LOG_GPS(DBG_ERR, "Error deregistering the client\n");
-
- return FALSE;
- }
+ if (err == CONNECTION_ERROR_NONE) {
+ set_connection_status(ACTIVATING);
+ LOG_GPS(DBG_LOW, "Sent PDP Activation.\n");
+ return TRUE;
} else {
- LOG_GPS(DBG_ERR, "NO Pdp Act Response or Some error in select.\n");
- noti_resp_deinit(pdp_pipe_fds);
-
- err = net_deregister_client();
- if (err == NET_ERR_NONE)
+ LOG_GPS(DBG_WARN, "Error in net_open_connection_with_preference() [%d]\n", err);
+ set_connection_status(DEACTIVATED);
+ err = connection_destroy(g_con);
+ if (err == CONNECTION_ERROR_NONE)
LOG_GPS(DBG_LOW, "Client deregistered successfully\n");
else
LOG_GPS(DBG_ERR, "Error deregistering the client\n");
+ noti_resp_deinit(pdp_pipe_fds);
return FALSE;
}
+
+
+}
+void connectio_close_cb(connection_error_e result, void* user_data)
+{
+ if (result == CONNECTION_ERROR_NONE) {
+ LOG_GPS(DBG_LOW, "DisConnected");
+ LOG_GPS(DBG_LOW, "Successful PDP Diactivation\n");
+ set_connection_status(DEACTIVATED);
+ pdp_proxy_conf();
+ noti_resp_noti(pdp_pipe_fds, TRUE);
+ if (noti_resp_wait(pdp_pipe_fds) > 0) {
+ if (noti_resp_check(pdp_pipe_fds))
+ LOG_GPS(DBG_LOW, "Close Connection success\n");
+ else
+ LOG_GPS(DBG_ERR, "Close connection failed\n");
+ }
+
+ noti_resp_deinit(pdp_pipe_fds);
+
+ set_connection_status(DEACTIVATED);
+
+ result = connection_destroy(g_con);
+ if (result == CONNECTION_ERROR_NONE) {
+ LOG_GPS(DBG_LOW, "Client deregistered successfully\n");
+ } else {
+ LOG_GPS(DBG_WARN, "Error deregistering the client\n");
+
+ }
+ } else {
+ LOG_GPS(DBG_ERR, " PDP DeActivation Failed - PDP Error[%d]\n", result);
+ set_connection_status(DEACTIVATED);
+ noti_resp_noti(pdp_pipe_fds, FALSE);
+ }
}
unsigned int stop_pdp_connection(void)
}
set_connection_status(DEACTIVATING);
- err = net_close_connection(profile_name);
- if (err == NET_ERR_NONE) {
+ err = connection_close_profile(g_con,g_profile,connectio_close_cb,NULL);
+ if (err == CONNECTION_ERROR_NONE) {
LOG_GPS(DBG_LOW, "Success net_close_connection\n");
} else {
LOG_GPS(DBG_WARN, "Error in sending net_close_connection error=%d\n", err);
noti_resp_deinit(pdp_pipe_fds);
return FALSE;
}
- if (noti_resp_wait(pdp_pipe_fds) > 0) {
- if (noti_resp_check(pdp_pipe_fds))
- LOG_GPS(DBG_LOW, "Close Connection success\n");
- else
- LOG_GPS(DBG_ERR, "Close connection failed\n");
- }
- noti_resp_deinit(pdp_pipe_fds);
-
- set_connection_status(DEACTIVATED);
-
- err = net_deregister_client();
- if (err == NET_ERR_NONE) {
- LOG_GPS(DBG_LOW, "Client deregistered successfully\n");
- } else {
- LOG_GPS(DBG_WARN, "Error deregistering the client\n");
- return FALSE;
- }
return TRUE;
}