2 * Copyright 2012-2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "MmsPluginConnManWrapper.h"
19 #include "MmsPluginDebug.h"
21 void network_print_profile(net_profile_info_t *ProfInfo)
25 unsigned char *ipaddr;
26 unsigned char *netmaskaddr;
27 unsigned char *gwaddr;
28 net_dev_info_t *net_info;
30 if (ProfInfo->profile_type == NET_DEVICE_CELLULAR) {
31 ipaddr = (unsigned char *)&ProfInfo->ProfileInfo.Pdp.net_info.IpAddr.Data.Ipv4.s_addr;
32 netmaskaddr = (unsigned char *)&ProfInfo->ProfileInfo.Pdp.net_info.SubnetMask.Data.Ipv4.s_addr;
33 gwaddr = (unsigned char *)&ProfInfo->ProfileInfo.Pdp.net_info.GatewayAddr.Data.Ipv4.s_addr;
34 net_info = &(ProfInfo->ProfileInfo.Pdp.net_info);
36 MSG_DEBUG("Error!!! Invalid profile type\n");
40 MSG_DEBUG("**************************************************************************************************");
42 MSG_DEBUG("Profile Name = [%s]\n", ProfInfo->ProfileName);
44 if (ProfInfo->ProfileState == NET_STATE_TYPE_IDLE)
45 MSG_DEBUG("Profile State = [idle]\n");
46 else if (ProfInfo->ProfileState == NET_STATE_TYPE_FAILURE)
47 MSG_DEBUG("Profile State = [failure]\n");
48 else if (ProfInfo->ProfileState == NET_STATE_TYPE_ASSOCIATION)
49 MSG_DEBUG("Profile State = [association]\n");
50 else if (ProfInfo->ProfileState == NET_STATE_TYPE_CONFIGURATION)
51 MSG_DEBUG("Profile State = [configuration]\n");
52 else if (ProfInfo->ProfileState == NET_STATE_TYPE_READY)
53 MSG_DEBUG("Profile State = [ready]\n");
54 else if (ProfInfo->ProfileState == NET_STATE_TYPE_ONLINE)
55 MSG_DEBUG("Profile State = [online]\n");
56 else if (ProfInfo->ProfileState == NET_STATE_TYPE_DISCONNECT)
57 MSG_DEBUG("Profile State = [disconnect]\n");
59 MSG_DEBUG("Profile State = [unknown]\n");
61 MSG_DEBUG("Profile Type = [pdp]\n");
63 if (ProfInfo->ProfileInfo.Pdp.ProtocolType == NET_PDP_TYPE_GPRS)
64 MSG_DEBUG("Profile Protocol Type = [GPRS]\n");
65 else if (ProfInfo->ProfileInfo.Pdp.ProtocolType == NET_PDP_TYPE_EDGE)
66 MSG_DEBUG("Profile Protocol Type = [EDGE]\n");
67 else if (ProfInfo->ProfileInfo.Pdp.ProtocolType == NET_PDP_TYPE_UMTS)
68 MSG_DEBUG("Profile Protocol Type = [UMTS]\n");
70 MSG_DEBUG("Profile Protocol Type = [NONE]\n");
72 MSG_DEBUG("Profile APN = [%s]\n", ProfInfo->ProfileInfo.Pdp.Apn);
74 if (ProfInfo->ProfileInfo.Pdp.AuthInfo.AuthType == NET_PDP_AUTH_PAP)
75 MSG_DEBUG("Profile Auth Type = [PAP]\n");
76 else if (ProfInfo->ProfileInfo.Pdp.AuthInfo.AuthType == NET_PDP_AUTH_CHAP)
77 MSG_DEBUG("Profile Auth Type = [CHAP]\n");
79 MSG_DEBUG("Profile Auth Type = [NONE]\n");
81 MSG_DEBUG("Profile Auth UserName = [%s]\n", ProfInfo->ProfileInfo.Pdp.AuthInfo.UserName);
82 MSG_DEBUG("Profile Auth Password = [%s]\n", ProfInfo->ProfileInfo.Pdp.AuthInfo.Password);
83 MSG_DEBUG("Profile Home URL = [%s]\n", ProfInfo->ProfileInfo.Pdp.HomeURL);
84 MSG_DEBUG("Profile MCC = [%s]\n", ProfInfo->ProfileInfo.Pdp.Mcc);
85 MSG_DEBUG("Profile MNC = [%s]\n", ProfInfo->ProfileInfo.Pdp.Mnc);
86 MSG_DEBUG("Profile Roaming = [%d]\n", (int)ProfInfo->ProfileInfo.Pdp.Roaming);
87 MSG_DEBUG("Profile Setup Required = [%d]\n", (int)ProfInfo->ProfileInfo.Pdp.SetupRequired);
88 MSG_DEBUG("Profile Favourite = [%d]\n", (int)ProfInfo->Favourite);
89 MSG_DEBUG("Profile Device Name = [%s]\n", net_info->DevName);
90 MSG_DEBUG("Profile DNS Count = [%d]\n", net_info->DnsCount);
91 for (di = 0; di < net_info->DnsCount; di++) {
92 unsigned char *dns = (unsigned char *)&net_info->DnsAddr[di].Data.Ipv4.s_addr;
93 MSG_DEBUG("Profile DNS Address %d = [%d.%d.%d.%d]\n", di+1, dns[0], dns[1], dns[2], dns[3]);
96 if (net_info->IpConfigType == NET_IP_CONFIG_TYPE_DYNAMIC)
97 MSG_DEBUG("Profile IPv4 Method = [NET_IP_CONFIG_TYPE_DYNAMIC]\n");
98 else if (net_info->IpConfigType == NET_IP_CONFIG_TYPE_STATIC)
99 MSG_DEBUG("Profile IPv4 Method = [NET_IP_CONFIG_TYPE_STATIC]\n");
100 else if (net_info->IpConfigType == NET_IP_CONFIG_TYPE_FIXED)
101 MSG_DEBUG("Profile IPv4 Method = [NET_IP_CONFIG_TYPE_FIXED]\n");
102 else if (net_info->IpConfigType == NET_IP_CONFIG_TYPE_OFF)
103 MSG_DEBUG("Profile IPv4 Method = [NET_IP_CONFIG_TYPE_OFF]\n");
105 MSG_DEBUG("Profile IPv4 Method = [UNKNOWN]\n");
107 MSG_DEBUG("Profile IP Address = [%d.%d.%d.%d]\n", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
108 MSG_DEBUG("Profile Netmask = [%d.%d.%d.%d]\n", netmaskaddr[0], netmaskaddr[1], netmaskaddr[2], netmaskaddr[3]);
109 MSG_DEBUG("Profile Gateway = [%d.%d.%d.%d]\n", gwaddr[0], gwaddr[1], gwaddr[2], gwaddr[3]);
111 if (net_info->ProxyMethod == NET_PROXY_TYPE_DIRECT)
112 MSG_DEBUG("Proxy Method = [direct]\n");
113 else if (net_info->ProxyMethod == NET_PROXY_TYPE_AUTO)
114 MSG_DEBUG("Proxy Method = [auto]\n");
115 else if (net_info->ProxyMethod == NET_PROXY_TYPE_MANUAL)
116 MSG_DEBUG("Proxy Method = [manual]\n");
118 MSG_DEBUG("Proxy Method = [unknown]\n");
120 MSG_DEBUG("Profile Proxy = [%s]\n", net_info->ProxyAddr);
122 MSG_DEBUG("**************************************************************************************************");
127 void network_evt_cb (net_event_info_t *event_cb, void *user_data)
131 MmsPluginCmAgent::instance()->processCBdatas(event_cb, user_data);
137 MmsPluginCmAgent *MmsPluginCmAgent::pInstance = NULL;
139 MmsPluginCmAgent *MmsPluginCmAgent::instance()
142 pInstance = new MmsPluginCmAgent();
147 MmsPluginCmAgent::MmsPluginCmAgent()
152 bzero(&mmsProfile, sizeof (net_profile_info_t));
157 MmsPluginCmAgent::~MmsPluginCmAgent()
162 bool MmsPluginCmAgent::registration()
166 bool registResult = true;
168 if (net_register_client((net_event_cb_t) network_evt_cb, NULL) != NET_ERR_NONE) {
169 MSG_DEBUG("Error!! net_register_client() failed.\n");
170 registResult = false;
178 bool MmsPluginCmAgent::open()
186 int netOpenResult = NET_ERR_NONE;
187 net_service_type_t service_type = NET_SERVICE_MMS;
189 netOpenResult = net_open_connection_with_preference(service_type);
190 if (netOpenResult != NET_ERR_NONE) {
191 MSG_DEBUG("Error!! net_open_connection_with_profile() failed. [%d]", netOpenResult);
196 MSG_DEBUG("WAITING UNTIL Network Connection Open.");
201 time_ret = cv.timedwait(mx.pMutex(), 50);
205 if (time_ret == ETIMEDOUT) {
206 MSG_DEBUG("Network Connection Open Time Out.");
211 MSG_DEBUG("Network connection open failed");
217 MSG_DEBUG("Network is already opened.");
227 void MmsPluginCmAgent::close()
232 int netOpenResult = NET_ERR_NONE;
234 netOpenResult = net_close_connection(mmsProfile.ProfileName);
235 if (netOpenResult != NET_ERR_NONE) {
236 MSG_DEBUG("Error!! net_close_connection() failed.\n");
241 MSG_DEBUG("WAITING UNTIL Network Connection Close.");
246 time_ret = cv.timedwait(mx.pMutex(), 50);
250 if (time_ret == ETIMEDOUT) {
251 MSG_DEBUG("Network Connection Close Timed Out.");
257 MSG_DEBUG ("Network Connection is not opened.");
263 void MmsPluginCmAgent::deregistration()
267 int netOpenResult = NET_ERR_NONE;
269 netOpenResult = net_deregister_client();
270 if (netOpenResult != NET_ERR_NONE)
271 MSG_DEBUG("Error!! net_deregister_client() failed. [%d]", netOpenResult);
273 MSG_DEBUG ("net_deregister_client() Success.");
279 void MmsPluginCmAgent::processCBdatas(net_event_info_t *event_cb, void *user_data)
283 net_dev_info_t *dev_info = NULL;
284 net_profile_info_t *prof_info = NULL;
286 switch (event_cb->Event) {
287 case NET_EVENT_NET_CONFIGURE_RSP:
288 MSG_DEBUG("Received Network Configuration response: %d \n", event_cb->Error);
289 dev_info = (net_dev_info_t *)event_cb->Data;
291 /*Successful PDP Activation*/
292 if (event_cb->Error == NET_ERR_NONE) {
293 char *ip = (char *)&dev_info->IpAddr.Data.Ipv4;
294 char *netmask = (char *)&dev_info->SubnetMask.Data.Ipv4;
295 char *gateway = (char *)&dev_info->GatewayAddr.Data.Ipv4;
296 char *dns1 = (char *)&dev_info->DnsAddr[0].Data.Ipv4.s_addr;
297 char *dns2 = (char *)&dev_info->DnsAddr[1].Data.Ipv4.s_addr;
299 MSG_DEBUG("= IP address [%d.%d.%d.%d]\n",
300 (int)ip[0], ip[1], ip[2], ip[3]);
301 MSG_DEBUG("= Netmask [%d.%d.%d.%d]\n",
302 (int)netmask[0], netmask[1], netmask[2], netmask[3]);
303 MSG_DEBUG("= Gateway [%d.%d.%d.%d]\n",
304 (int)gateway[0], gateway[1], gateway[2], gateway[3]);
305 MSG_DEBUG("= DNS address [%d.%d.%d.%d]\n",
306 (int)dns1[0], dns1[1], dns1[2], dns1[3]);
307 MSG_DEBUG("= DNS2 address [%d.%d.%d.%d]\n",
308 (int)dns2[0], dns2[1], dns2[2], dns2[3]);
309 MSG_DEBUG("= Device name [%s]\n", dev_info->DevName);
310 MSG_DEBUG("= Profile name [%s]\n", dev_info->ProfileName);
312 MSG_DEBUG("Error!!! Network Configuration Failed %d \n", event_cb->Error);
316 /*Response from Datacom for PDP Activation Request*/
317 case NET_EVENT_OPEN_IND:
318 MSG_DEBUG("Got Open Indication\n");
319 MSG_DEBUG("Received ACTIVATION response: %d \n", event_cb->Error);
321 case NET_EVENT_OPEN_RSP:
322 MSG_DEBUG("Got Open RSP\n");
323 MSG_DEBUG("Received ACTIVATION response: %d \n", event_cb->Error);
324 prof_info = (net_profile_info_t *)event_cb->Data;
326 /*Successful PDP Activation*/
327 if (event_cb->Error == NET_ERR_NONE || event_cb->Error == NET_ERR_ACTIVE_CONNECTION_EXISTS) {
328 network_print_profile(prof_info);
332 memcpy(&mmsProfile, prof_info, sizeof(net_profile_info_t));
338 MSG_DEBUG("Activation Failed %d \n", event_cb->Error); // open failed
346 case NET_EVENT_CLOSE_RSP:
347 MSG_DEBUG("Got Close RSP\n");
351 bzero(&mmsProfile, sizeof(net_profile_info_t));
358 case NET_EVENT_CLOSE_IND:
359 MSG_DEBUG("Got Close IND\n");
361 case NET_EVENT_PROFILE_MODIFY_IND:
362 MSG_DEBUG("Received Profile modified Indication\n");
363 MSG_DEBUG("No. of profile [%d]\n", event_cb->Datalength);
365 case NET_EVENT_NET_STATE_IND:
366 MSG_DEBUG("Received NET_EVENT_NET_STATE_IND\n");
369 MSG_DEBUG("Error! Unknown Event = %d\n\n", event_cb->Event);
377 bool MmsPluginCmAgent::getDeviceName(char *deviceName)
382 int deviceNameLength = strlen(mmsProfile.ProfileInfo.Pdp.net_info.DevName);
384 if (deviceNameLength > 0) {
385 strncpy(deviceName, mmsProfile.ProfileInfo.Pdp.net_info.DevName, deviceNameLength);
386 deviceName[deviceNameLength] = '\0';
394 bool MmsPluginCmAgent::getHomeURL(char *homeURL)
399 int homeURLLength = strlen(mmsProfile.ProfileInfo.Pdp.HomeURL);
401 if (homeURLLength > 0) {
402 strncpy(homeURL, mmsProfile.ProfileInfo.Pdp.HomeURL, homeURLLength);
403 homeURL[homeURLLength] = '\0';
411 bool MmsPluginCmAgent::getProxyAddr(char *proxyAddr)
416 int proxyAddrLength = strlen(mmsProfile.ProfileInfo.Pdp.net_info.ProxyAddr);
418 if (proxyAddrLength > 0) {
419 if (strchr(mmsProfile.ProfileInfo.Pdp.net_info.ProxyAddr, ':') == NULL)
422 proxyAddrLength = proxyAddrLength - strlen(strchr(mmsProfile.ProfileInfo.Pdp.net_info.ProxyAddr, ':'));
423 strncpy(proxyAddr, mmsProfile.ProfileInfo.Pdp.net_info.ProxyAddr, proxyAddrLength);
424 proxyAddr[proxyAddrLength] = '\0';
433 int MmsPluginCmAgent::getProxyPort()
438 int proxyAddrLength = strlen(mmsProfile.ProfileInfo.Pdp.net_info.ProxyAddr);
440 if (proxyAddrLength > 0) {
441 char *pPort = strchr(mmsProfile.ProfileInfo.Pdp.net_info.ProxyAddr, ':') + 1;
442 /* pPort cannot be NULL */