02fc8c74e87cdee9f1ce7dda3a1e99e83e1c5586
[platform/core/api/connection.git] / unittest / mock / connection-mock.c
1 //
2 // Copyright (c) 2020 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <stdbool.h>
19 #include <string.h>
20
21 #include <system_info.h>
22 #include <glib.h>
23 #include <gio/gio.h>
24 #include <arpa/inet.h>
25 #include <vconf/vconf.h>
26
27 #include "net_connection_private.h"
28
29 #ifndef API
30 #define API __attribute__ ((visibility("default")))
31 #endif
32
33 struct cellular_profile_s {
34         char *obj;
35         char *name;
36         net_state_type_t state;
37         net_state_type_t state6;
38         char *interface;
39         char *address;
40         net_ip_config_type_t ipv4_method;
41         char *ipv4_address;
42         char *ipv4_netmask;
43         char *ipv4_gateway;
44         net_ip_config_type_t ipv6_method;
45         net_service_type_t service_type;
46         char *apn;
47         char *proxy_addr;
48         char *home_url;
49         char *profile_name;
50         bool hidden;
51         bool editable;
52         bool default_conn;
53 } cellular_profile[] = {
54         {
55                 "/net/connman/service/cellular_sprdmodem0_45005_534b2054656c65636f6d_1164_1",
56                 "534b2054656c65636f6d_1164_1",
57                 NET_STATE_TYPE_READY,
58                 NET_STATE_TYPE_IDLE,
59                 "seth_w0",
60                 "6A:99:73:18:BF:62",
61                 NET_IP_CONFIG_TYPE_FIXED,
62                 "10.37.107.10",
63                 "255.255.255.255",
64                 "10.37.107.1",
65                 0,
66                 NET_SERVICE_INTERNET,
67                 "lte.sktelecom.com",
68                 NULL,
69                 NULL,
70                 "SK Telecom",
71                 FALSE,
72                 TRUE,
73                 TRUE,
74         },
75         {
76                 "/net/connman/service/cellular_sprdmodem0_45005_534b2054656c65636f6d_1165_2",
77                 "534b2054656c65636f6d_1165_2",
78                 NET_STATE_TYPE_IDLE,
79                 NET_STATE_TYPE_IDLE,
80                 NULL,
81                 NULL,
82                 0,
83                 NULL,
84                 NULL,
85                 NULL,
86                 0,
87                 NET_SERVICE_MMS,
88                 "lte.sktelecom.com",
89                 "lteoma.nate.com:9093",
90                 "http://omms.nate.com:9082/oma_mms",
91                 "SK Telecom",
92                 FALSE,
93                 TRUE,
94                 TRUE,
95         },
96 };
97
98 struct wifi_profile_s {
99         char *obj;
100         wlan_security_mode_type_t sec_mode;
101         wlan_encryption_mode_type_t enc_mode;
102         gboolean passpoint;
103         unsigned char strength;
104         char essid[NET_WLAN_ESSID_LEN + 1];
105         char bssid[NET_MAX_MAC_ADDR_LEN + 1];
106         int max_rate;
107         unsigned int frequency;
108         unsigned int keymgmt;
109         net_state_type_t state;
110         net_state_type_t state6;
111         char *interface;
112         char *address;
113         net_ip_config_type_t ipv4_method;
114         char *ipv4_address;
115         char *ipv4_netmask;
116         char *ipv4_gateway;
117         net_ip_config_type_t ipv6_method;
118 } wifi_profile[] = {
119         {
120                 "/net/connman/service/wifi_f8d11162c728_4e4554474541523839_managed_psk",
121                 WLAN_SEC_MODE_WPA2_PSK,
122                 WLAN_ENC_MODE_AES,
123                 FALSE,
124                 71,
125                 "NETGEAR89",
126                 "9c:3d:cf:f7:bb:35",
127                 1,
128                 2462,
129                 520,
130                 NET_STATE_TYPE_READY,
131                 NET_STATE_TYPE_CONFIGURATION,
132                 "wlan0",
133                 "F8:D1:11:62:C7:28",
134                 NET_IP_CONFIG_TYPE_DYNAMIC,
135                 "192.168.1.4",
136                 "255.255.255.0",
137                 "192.168.1.1",
138                 NET_IP_CONFIG_TYPE_AUTO_IP,
139         },
140         {
141                 "/net/connman/service/wifi_f8d11162c728_545431_managed_psk",
142                 WLAN_SEC_MODE_WPA2_PSK,
143                 WLAN_ENC_MODE_WEP,
144                 TRUE,
145                 73,
146                 "TT1",
147                 "60:45:cb:cc:05:d0",
148                 54000000,
149                 2457,
150                 8,
151                 NET_STATE_TYPE_IDLE,
152                 NET_STATE_TYPE_IDLE,
153                 "wlan0",
154                 "F8:D1:11:62:C7:28",
155                 NET_IP_CONFIG_TYPE_DYNAMIC,
156                 NULL,
157                 NULL,
158                 NULL,
159                 NET_IP_CONFIG_TYPE_AUTO_IP,
160         },
161 };
162
163 struct ethernet_profile_s {
164         char *obj;
165         net_state_type_t state;
166         net_state_type_t state6;
167         char *interface;
168         char *address;
169         net_ip_config_type_t ipv4_method;
170         char *ipv4_address;
171         char *ipv4_netmask;
172         char *ipv4_gateway;
173         net_ip_config_type_t ipv6_method;
174 } ethernet_profile[] = {
175         {
176                 "/net/connman/service/ethernet_dca632888ceb_cable",
177                 NET_STATE_TYPE_READY,
178                 NET_STATE_TYPE_CONFIGURATION,
179                 "eth0",
180                 "DC:A6:32:88:8C:EB",
181                 NET_IP_CONFIG_TYPE_AUTO_IP,
182                 "169.254.104.67",
183                 "255.255.0.0",
184                 NULL,
185                 NET_IP_CONFIG_TYPE_AUTO_IP,
186         },
187 };
188
189 /* system info */
190 API int system_info_get_platform_bool(const char *key, bool *value)
191 {
192         *value = TRUE;
193         return SYSTEM_INFO_ERROR_NONE;
194 }
195
196 API int system_info_get_platform_string(const char *key, char **value)
197 {
198         if (g_strcmp0(key, "http://tizen.org/feature/profile") == 0)
199                 *value = g_strdup("m");
200
201         return SYSTEM_INFO_ERROR_NONE;
202 }
203
204 /* vconf */
205 API char *vconf_get_str(const char *in_key)
206 {
207         if (g_strcmp0(in_key, VCONFKEY_NETWORK_IP) == 0)
208                 return g_strdup("192.168.1.4");
209         else if (g_strcmp0(in_key, VCONFKEY_NETWORK_IP6) == 0)
210                 return g_strdup(" ");
211         else if (g_strcmp0(in_key, VCONFKEY_NETWORK_PROXY) == 0)
212                 return g_strdup(" ");
213         else if (g_strcmp0(in_key, VCONFKEY_WIFI_BSSID_ADDRESS) == 0)
214                 return g_strdup("f8:d1:11:62:c7:28");
215
216         return NULL;
217 }
218
219 API int vconf_get_int(const char *in_key, int *intval)
220 {
221         if (g_strcmp0(in_key, VCONFKEY_NETWORK_STATUS) == 0)
222                 *intval = 1;
223         else if (g_strcmp0(in_key, VCONFKEY_NETWORK_CELLULAR_STATE) == 0)
224                 *intval = 0;
225         else if (g_strcmp0(in_key, VCONF_TELEPHONY_DEFAULT_DATA_SERVICE) == 0)
226                 *intval = 0;
227         else if (g_strcmp0(in_key, VCONFKEY_DNET_STATE) == 0)
228                 *intval = 1;
229         else if (g_strcmp0(in_key, VCONFKEY_DNET_STATE2) == 0)
230                 *intval = 0;
231         else if (g_strcmp0(in_key, VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT) == 0)
232                 *intval = 0;
233         else if (g_strcmp0(in_key, VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV) == 0)
234                 *intval = 0;
235         else if (g_strcmp0(in_key, VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT) == 0)
236                 *intval = 1024;
237         else if (g_strcmp0(in_key, VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV) == 0)
238                 *intval = 2048;
239         else if (g_strcmp0(in_key, VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2) == 0)
240                 *intval = 0;
241         else if (g_strcmp0(in_key, VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2) == 0)
242                 *intval = 0;
243         else if (g_strcmp0(in_key, VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT2) == 0)
244                 *intval = 0;
245         else if (g_strcmp0(in_key, VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV2) == 0)
246                 *intval = 0;
247
248         return VCONF_OK;
249 }
250
251 /* libnet-client */
252 API int net_check_profile_privilege(void)
253 {
254         return NET_ERR_NONE;
255 }
256
257 API int net_check_get_privilege(void)
258 {
259         return NET_ERR_NONE;
260 }
261
262 API int net_check_set_privilege(void)
263 {
264         return NET_ERR_NONE;
265 }
266
267 API int net_register_client(void **handle, net_event_cb_t event_cb, void *user_data)
268 {
269         return NET_ERR_NONE;
270 }
271
272 API void net_deregister_client(void *handle)
273 {
274         return;
275 }
276
277 API int net_get_metered_state(void *handle, int *state)
278 {
279         *state = TRUE;
280         return NET_ERR_NONE;
281 }
282
283 API int net_get_wifi_state(void *handle, net_wifi_state_t *current_state)
284 {
285         *current_state = WIFI_CONNECTED;
286         return NET_ERR_NONE;
287 }
288
289 API int net_get_wifi_interface_list(void *handle, GSList **interface_list)
290 {
291         *interface_list = g_slist_append(*interface_list,
292                 g_strdup("dummy_ifname"));
293         return NET_ERR_NONE;
294 }
295
296 static void __net_init_profile_info(net_device_t profile_type, net_profile_info_t *ProfInfo)
297 {
298         int i = 0;
299         net_dev_info_t *net_info = NULL;
300
301         memset(ProfInfo, 0, sizeof(net_profile_info_t));
302         ProfInfo->Favourite = (char)FALSE;
303
304         if (profile_type == NET_DEVICE_WIFI) {
305                 ProfInfo->profile_type = NET_DEVICE_WIFI;
306                 ProfInfo->ProfileInfo.Wlan.Strength = 0;
307                 ProfInfo->ProfileInfo.Wlan.frequency = 0;
308                 ProfInfo->ProfileInfo.Wlan.max_rate = 0;
309                 ProfInfo->ProfileInfo.Wlan.wlan_mode = 0;
310                 ProfInfo->ProfileInfo.Wlan.PassphraseRequired = FALSE;
311                 ProfInfo->ProfileInfo.Wlan.security_info.sec_mode = 0;
312                 ProfInfo->ProfileInfo.Wlan.security_info.enc_mode = 0;
313                 ProfInfo->ProfileInfo.Wlan.security_info.wps_support = FALSE;
314
315                 net_info = &(ProfInfo->ProfileInfo.Wlan.net_info);
316         } else if (profile_type == NET_DEVICE_CELLULAR) {
317                 ProfInfo->profile_type = NET_DEVICE_CELLULAR;
318                 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_NONE;
319                 ProfInfo->ProfileInfo.Pdp.ServiceType = NET_SERVICE_UNKNOWN;
320                 ProfInfo->ProfileInfo.Pdp.PdnType = NET_PDN_TYPE_UNKNOWN;
321                 ProfInfo->ProfileInfo.Pdp.RoamPdnType = NET_PDN_TYPE_UNKNOWN;
322                 ProfInfo->ProfileInfo.Pdp.AuthInfo.AuthType = NET_PDP_AUTH_NONE;
323                 ProfInfo->ProfileInfo.Pdp.IsStatic = FALSE;
324                 ProfInfo->ProfileInfo.Pdp.Roaming = FALSE;
325                 ProfInfo->ProfileInfo.Pdp.SetupRequired = FALSE;
326                 ProfInfo->ProfileInfo.Pdp.Hidden = FALSE;
327                 ProfInfo->ProfileInfo.Pdp.Editable = TRUE;
328                 ProfInfo->ProfileInfo.Pdp.DefaultConn = FALSE;
329
330                 net_info = &(ProfInfo->ProfileInfo.Pdp.net_info);
331         } else if (profile_type == NET_DEVICE_ETHERNET) {
332                 net_info = &(ProfInfo->ProfileInfo.Ethernet.net_info);
333         } else if (profile_type == NET_DEVICE_BLUETOOTH) {
334                 net_info = &(ProfInfo->ProfileInfo.Bluetooth.net_info);
335         } else if (profile_type == NET_DEVICE_MESH) {
336                 ProfInfo->profile_type = NET_DEVICE_MESH;
337                 ProfInfo->ProfileInfo.Mesh.Strength = 0;
338                 ProfInfo->ProfileInfo.Mesh.frequency = 0;
339                 ProfInfo->ProfileInfo.Mesh.PassphraseRequired = FALSE;
340                 ProfInfo->ProfileInfo.Mesh.security_info.sec_mode = 0;
341
342                 net_info = &(ProfInfo->ProfileInfo.Mesh.net_info);
343         }
344
345         if (net_info != NULL) {
346                 net_info->DnsCount = 0;
347
348                 for (i = 0; i < NET_DNS_ADDR_MAX; i++) {
349                         net_info->DnsAddr[i].Type = NET_ADDR_IPV4;
350                         net_info->DnsAddr[i].Data.Ipv4.s_addr = 0;
351                 }
352
353                 net_info->IpConfigType = 0;
354                 net_info->IpAddr.Type = NET_ADDR_IPV4;
355                 net_info->IpAddr.Data.Ipv4.s_addr = 0;
356                 net_info->BNetmask = FALSE;
357                 net_info->SubnetMask.Type = NET_ADDR_IPV4;
358                 net_info->SubnetMask.Data.Ipv4.s_addr = 0;
359                 net_info->BDefGateway = FALSE;
360                 net_info->GatewayAddr.Type = NET_ADDR_IPV4;
361                 net_info->GatewayAddr.Data.Ipv4.s_addr = 0;
362                 net_info->BServerAddr = FALSE;
363                 net_info->ServerAddr.Type = NET_ADDR_IPV4;
364                 net_info->ServerAddr.Data.Ipv4.s_addr = 0;
365
366                 net_info->IpConfigType6 = 0;
367                 net_info->IpAddr6.Type = NET_ADDR_IPV6;
368                 inet_pton(AF_INET6, "::", &net_info->IpAddr6.Data.Ipv6);
369                 net_info->PrefixLen6 = 0;
370                 net_info->BDefGateway6 = FALSE;
371                 net_info->GatewayAddr6.Type = NET_ADDR_IPV6;
372                 inet_pton(AF_INET6, "::", &net_info->GatewayAddr6.Data.Ipv6);
373
374                 net_info->ProxyMethod = NET_PROXY_TYPE_UNKNOWN;
375         }
376 }
377
378 static void __net_extract_ip(char *ip, net_addr_t *ipAddr)
379 {
380         unsigned char *ipValue = NULL;
381         char *saveptr = NULL;
382         char ipString[NETPM_IPV4_STR_LEN_MAX+1];
383         char *ipToken[4];
384
385         ipValue = (unsigned char *)&(ipAddr->Data.Ipv4.s_addr);
386
387         g_strlcpy(ipString, ip, NETPM_IPV4_STR_LEN_MAX+1);
388
389         ipToken[0] = strtok_r(ipString, ".", &saveptr);
390
391         if (ipToken[0] != NULL) {
392                 ipToken[1] = strtok_r(NULL, ".", &saveptr);
393
394                 if (ipToken[1] != NULL) {
395                         ipToken[2] = strtok_r(NULL, ".", &saveptr);
396
397                         if (ipToken[2] != NULL) {
398                                 ipToken[3] = strtok_r(NULL, ".", &saveptr);
399
400                                 if (ipToken[3] != NULL) {
401                                         ipValue[0] = (unsigned char)atoi(ipToken[0]);
402                                         ipValue[1] = (unsigned char)atoi(ipToken[1]);
403                                         ipValue[2] = (unsigned char)atoi(ipToken[2]);
404                                         ipValue[3] = (unsigned char)atoi(ipToken[3]);
405                                 }
406                         }
407                 }
408         }
409 }
410
411 static int __net_get_prefix_len(char *netmask)
412 {
413         in_addr_t mask = inet_network(netmask);
414         int prefix_len = 0;
415
416         for (; mask; mask <<= 1)
417                 ++prefix_len;
418
419         return prefix_len;
420 }
421
422 static void __net_add_profile_cellular(net_profile_info_t **profile_info, int *profile_count)
423 {
424         int i;
425         net_profile_info_t *ProfilePtr = NULL;
426         int prof_cnt = sizeof(cellular_profile) / sizeof(struct cellular_profile_s);
427
428         for (i = 0; i < prof_cnt; ++i) {
429                 net_profile_info_t ProfInfo = { 0, };
430                 memset(&ProfInfo, 0, sizeof(net_profile_info_t));
431
432                 __net_init_profile_info(NET_DEVICE_CELLULAR, &ProfInfo);
433
434                 ProfInfo.profile_type = NET_DEVICE_CELLULAR;
435                 g_strlcpy(ProfInfo.ProfileName, cellular_profile[i].obj, NET_PROFILE_NAME_LEN_MAX);
436
437                 g_strlcpy(ProfInfo.ProfileInfo.Pdp.net_info.ProfileName,
438                         cellular_profile[i].obj, NET_PROFILE_NAME_LEN_MAX);
439                 g_strlcpy(ProfInfo.ProfileInfo.Pdp.PSModemPath,
440                         cellular_profile[i].name, NET_PROFILE_NAME_LEN_MAX);
441                 ProfInfo.ProfileState = cellular_profile[i].state;
442                 ProfInfo.ProfileState6 = cellular_profile[i].state6;
443
444                 net_dev_info_t *net_info = &(ProfInfo.ProfileInfo.Pdp.net_info);
445
446                 if (cellular_profile[i].interface)
447                         g_strlcpy(net_info->DevName, cellular_profile[i].interface, NET_MAX_DEVICE_NAME_LEN);
448                 if (cellular_profile[i].address)
449                         g_strlcpy(net_info->MacAddr, cellular_profile[i].address, NET_MAX_MAC_ADDR_LEN);
450                 if (cellular_profile[i].ipv4_method)
451                         net_info->IpConfigType = cellular_profile[i].ipv4_method;
452                 if (cellular_profile[i].ipv4_address)
453                         __net_extract_ip(cellular_profile[i].ipv4_address, &net_info->IpAddr);
454                 if (cellular_profile[i].ipv4_netmask) {
455                         __net_extract_ip(cellular_profile[i].ipv4_netmask, &net_info->SubnetMask);
456                         net_info->PrefixLen = __net_get_prefix_len(cellular_profile[i].ipv4_netmask);
457                         net_info->BNetmask = TRUE;
458                 }
459                 if (cellular_profile[i].ipv4_gateway) {
460                         __net_extract_ip(cellular_profile[i].ipv4_gateway, &net_info->GatewayAddr);
461                         net_info->BDefGateway = TRUE;
462                 }
463                 if (cellular_profile[i].ipv6_method)
464                         net_info->IpConfigType6 = cellular_profile[i].ipv6_method;
465
466                 ProfInfo.ProfileInfo.Pdp.ServiceType = cellular_profile[i].service_type;
467                 if (cellular_profile[i].apn)
468                         g_strlcpy(ProfInfo.ProfileInfo.Pdp.Apn, cellular_profile[i].apn, NET_PDP_APN_LEN_MAX);
469                 if (cellular_profile[i].proxy_addr)
470                         g_strlcpy(ProfInfo.ProfileInfo.Pdp.net_info.ProxyAddr,
471                                 cellular_profile[i].proxy_addr, NET_PROXY_LEN_MAX);
472                 if (cellular_profile[i].home_url)
473                         g_strlcpy(ProfInfo.ProfileInfo.Pdp.HomeURL, cellular_profile[i].home_url, NET_HOME_URL_LEN_MAX);
474                 if (cellular_profile[i].profile_name)
475                         g_strlcpy(ProfInfo.ProfileInfo.Pdp.Keyword, cellular_profile[i].profile_name, NET_PDP_APN_LEN_MAX);
476
477                 ProfInfo.ProfileInfo.Pdp.Hidden = cellular_profile[i].hidden;
478                 ProfInfo.ProfileInfo.Pdp.Editable = cellular_profile[i].editable;
479                 ProfInfo.ProfileInfo.Pdp.DefaultConn = cellular_profile[i].default_conn;
480
481                 ProfilePtr = (net_profile_info_t *)realloc(ProfilePtr, (i + 1) * sizeof(net_profile_info_t));
482                 memcpy(ProfilePtr + i, &ProfInfo, sizeof(net_profile_info_t));
483         }
484
485         *profile_count = prof_cnt;
486         *profile_info = ProfilePtr;
487 }
488
489 static void __net_add_default_profile_cellular(net_profile_info_t *ProfInfo)
490 {
491         __net_init_profile_info(NET_DEVICE_CELLULAR, ProfInfo);
492
493         ProfInfo->profile_type = NET_DEVICE_CELLULAR;
494         g_strlcpy(ProfInfo->ProfileName, cellular_profile[0].obj, NET_PROFILE_NAME_LEN_MAX);
495
496         g_strlcpy(ProfInfo->ProfileInfo.Pdp.net_info.ProfileName,
497                 cellular_profile[0].obj, NET_PROFILE_NAME_LEN_MAX);
498         g_strlcpy(ProfInfo->ProfileInfo.Pdp.PSModemPath,
499                 cellular_profile[0].name, NET_PROFILE_NAME_LEN_MAX);
500         ProfInfo->ProfileState = cellular_profile[0].state;
501         ProfInfo->ProfileState6 = cellular_profile[0].state6;
502
503         net_dev_info_t *net_info = &(ProfInfo->ProfileInfo.Pdp.net_info);
504
505         if (cellular_profile[0].interface)
506                 g_strlcpy(net_info->DevName, cellular_profile[0].interface, NET_MAX_DEVICE_NAME_LEN);
507         if (cellular_profile[0].address)
508                 g_strlcpy(net_info->MacAddr, cellular_profile[0].address, NET_MAX_MAC_ADDR_LEN);
509         if (cellular_profile[0].ipv4_method)
510                 net_info->IpConfigType = cellular_profile[0].ipv4_method;
511         if (cellular_profile[0].ipv4_address)
512                 __net_extract_ip(cellular_profile[0].ipv4_address, &net_info->IpAddr);
513         if (cellular_profile[0].ipv4_netmask) {
514                 __net_extract_ip(cellular_profile[0].ipv4_netmask, &net_info->SubnetMask);
515                 net_info->PrefixLen = __net_get_prefix_len(cellular_profile[0].ipv4_netmask);
516                 net_info->BNetmask = TRUE;
517         }
518         if (cellular_profile[0].ipv4_gateway) {
519                 __net_extract_ip(cellular_profile[0].ipv4_gateway, &net_info->GatewayAddr);
520                 net_info->BDefGateway = TRUE;
521         }
522         if (cellular_profile[0].ipv6_method)
523                 net_info->IpConfigType6 = cellular_profile[0].ipv6_method;
524
525         ProfInfo->ProfileInfo.Pdp.ServiceType = cellular_profile[0].service_type;
526         if (cellular_profile[0].apn)
527                 g_strlcpy(ProfInfo->ProfileInfo.Pdp.Apn, cellular_profile[0].apn, NET_PDP_APN_LEN_MAX);
528         if (cellular_profile[0].proxy_addr)
529                 g_strlcpy(ProfInfo->ProfileInfo.Pdp.net_info.ProxyAddr,
530                         cellular_profile[0].proxy_addr, NET_PROXY_LEN_MAX);
531         if (cellular_profile[0].home_url)
532                 g_strlcpy(ProfInfo->ProfileInfo.Pdp.HomeURL, cellular_profile[0].home_url, NET_HOME_URL_LEN_MAX);
533         if (cellular_profile[0].profile_name)
534                 g_strlcpy(ProfInfo->ProfileInfo.Pdp.Keyword, cellular_profile[0].profile_name, NET_PDP_APN_LEN_MAX);
535
536         ProfInfo->ProfileInfo.Pdp.Hidden = cellular_profile[0].hidden;
537         ProfInfo->ProfileInfo.Pdp.Editable = cellular_profile[0].editable;
538         ProfInfo->ProfileInfo.Pdp.DefaultConn = cellular_profile[0].default_conn;
539 }
540
541 static void __net_add_profile_wifi(net_profile_info_t **profile_info, int *profile_count)
542 {
543         int i;
544         net_profile_info_t *ProfilePtr = NULL;
545         int prof_cnt = sizeof(wifi_profile) / sizeof(struct wifi_profile_s);
546
547         for (i = 0; i < prof_cnt; ++i) {
548                 net_profile_info_t ProfInfo = { 0, };
549                 memset(&ProfInfo, 0, sizeof(net_profile_info_t));
550
551                 __net_init_profile_info(NET_DEVICE_WIFI, &ProfInfo);
552
553                 ProfInfo.profile_type = NET_DEVICE_WIFI;
554                 g_strlcpy(ProfInfo.ProfileName, wifi_profile[i].obj, NET_PROFILE_NAME_LEN_MAX);
555
556                 ProfInfo.ProfileState = wifi_profile[i].state;
557                 ProfInfo.ProfileState6 = wifi_profile[i].state6;
558
559                 net_wifi_profile_info_t *Wlan = &(ProfInfo.ProfileInfo.Wlan);
560
561                 g_strlcpy(Wlan->net_info.ProfileName, wifi_profile[i].obj, NET_PROFILE_NAME_LEN_MAX);
562                 Wlan->security_info.sec_mode = wifi_profile[i].sec_mode;
563                 Wlan->security_info.enc_mode = wifi_profile[i].enc_mode;
564                 Wlan->passpoint = wifi_profile[i].passpoint;
565                 Wlan->Strength = wifi_profile[i].strength;
566                 if (wifi_profile[i].essid)
567                         g_strlcpy(Wlan->essid, wifi_profile[i].essid, NET_WLAN_ESSID_LEN);
568                 if (wifi_profile[i].bssid)
569                         g_strlcpy(Wlan->bssid, wifi_profile[i].bssid, NET_MAX_MAC_ADDR_LEN);
570                 Wlan->max_rate = wifi_profile[i].max_rate;
571                 Wlan->frequency = wifi_profile[i].frequency;
572                 Wlan->security_info.keymgmt = wifi_profile[i].keymgmt;
573
574                 net_dev_info_t *net_info = &(ProfInfo.ProfileInfo.Wlan.net_info);
575
576                 if (wifi_profile[i].interface)
577                         g_strlcpy(net_info->DevName, wifi_profile[i].interface, NET_MAX_DEVICE_NAME_LEN);
578                 if (wifi_profile[i].address)
579                         g_strlcpy(net_info->MacAddr, wifi_profile[i].address, NET_MAX_MAC_ADDR_LEN);
580                 if (wifi_profile[i].ipv4_method)
581                         net_info->IpConfigType = wifi_profile[i].ipv4_method;
582                 if (wifi_profile[i].ipv4_address)
583                         __net_extract_ip(wifi_profile[i].ipv4_address, &net_info->IpAddr);
584                 if (wifi_profile[i].ipv4_netmask) {
585                         __net_extract_ip(wifi_profile[i].ipv4_netmask, &net_info->SubnetMask);
586                         net_info->PrefixLen = __net_get_prefix_len(wifi_profile[i].ipv4_netmask);
587                         net_info->BNetmask = TRUE;
588                 }
589                 if (wifi_profile[i].ipv4_gateway) {
590                         __net_extract_ip(wifi_profile[i].ipv4_gateway, &net_info->GatewayAddr);
591                         net_info->BDefGateway = TRUE;
592                 }
593                 if (wifi_profile[i].ipv6_method)
594                         net_info->IpConfigType6 = wifi_profile[i].ipv6_method;
595
596                 ProfilePtr = (net_profile_info_t *)realloc(ProfilePtr, (i + 1) * sizeof(net_profile_info_t));
597                 memcpy(ProfilePtr + i, &ProfInfo, sizeof(net_profile_info_t));
598         }
599
600         *profile_count = prof_cnt;
601         *profile_info = ProfilePtr;
602 }
603
604 static void __net_add_profile_ethernet(net_profile_info_t **profile_info, int *profile_count)
605 {
606         int i;
607         net_profile_info_t *ProfilePtr = NULL;
608         int prof_cnt = sizeof(ethernet_profile) / sizeof(struct ethernet_profile_s);
609
610         for (i = 0; i < prof_cnt; ++i) {
611                 net_profile_info_t ProfInfo = { 0, };
612                 memset(&ProfInfo, 0, sizeof(net_profile_info_t));
613
614                 __net_init_profile_info(NET_DEVICE_ETHERNET, &ProfInfo);
615
616                 ProfInfo.profile_type = NET_DEVICE_ETHERNET;
617                 g_strlcpy(ProfInfo.ProfileName, ethernet_profile[i].obj, NET_PROFILE_NAME_LEN_MAX);
618
619                 ProfInfo.ProfileState = ethernet_profile[i].state;
620                 ProfInfo.ProfileState6 = ethernet_profile[i].state6;
621
622                 net_dev_info_t *net_info = &(ProfInfo.ProfileInfo.Wlan.net_info);
623
624                 if (ethernet_profile[i].interface)
625                         g_strlcpy(net_info->DevName, ethernet_profile[i].interface, NET_MAX_DEVICE_NAME_LEN);
626                 if (ethernet_profile[i].address)
627                         g_strlcpy(net_info->MacAddr, ethernet_profile[i].address, NET_MAX_MAC_ADDR_LEN);
628                 if (ethernet_profile[i].ipv4_method)
629                         net_info->IpConfigType = ethernet_profile[i].ipv4_method;
630                 if (ethernet_profile[i].ipv4_address)
631                         __net_extract_ip(ethernet_profile[i].ipv4_address, &net_info->IpAddr);
632                 if (ethernet_profile[i].ipv4_netmask) {
633                         __net_extract_ip(ethernet_profile[i].ipv4_netmask, &net_info->SubnetMask);
634                         net_info->PrefixLen = __net_get_prefix_len(ethernet_profile[i].ipv4_netmask);
635                         net_info->BNetmask = TRUE;
636                 }
637                 if (ethernet_profile[i].ipv4_gateway) {
638                         __net_extract_ip(ethernet_profile[i].ipv4_gateway, &net_info->GatewayAddr);
639                         net_info->BDefGateway = TRUE;
640                 }
641                 if (ethernet_profile[i].ipv6_method)
642                         net_info->IpConfigType6 = ethernet_profile[i].ipv6_method;
643
644                 ProfilePtr = (net_profile_info_t *)realloc(ProfilePtr, (i + 1) * sizeof(net_profile_info_t));
645                 memcpy(ProfilePtr + i, &ProfInfo, sizeof(net_profile_info_t));
646         }
647
648         *profile_count = prof_cnt;
649         *profile_info = ProfilePtr;
650 }
651
652 API int net_get_profile_list(void *handle, net_device_t device_type,
653                 net_profile_info_t **profile_list, int *profile_cnt)
654 {
655         int cellular_cnt = 0;
656         int wifi_cnt = 0;
657         int ethernet_cnt = 0;
658         net_profile_info_t *cellular_profiles = NULL;
659         net_profile_info_t *wifi_profiles = NULL;
660         net_profile_info_t *ethernet_profiles = NULL;
661         net_profile_info_t *profiles = NULL;
662
663         *profile_cnt = 0;
664
665         switch (device_type) {
666         case NET_DEVICE_CELLULAR:
667                 __net_add_profile_cellular(&cellular_profiles, &cellular_cnt);
668                 *profile_cnt += cellular_cnt;
669                 break;
670         case NET_DEVICE_WIFI:
671                 __net_add_profile_wifi(&wifi_profiles, &wifi_cnt);
672                 *profile_cnt += wifi_cnt;
673                 break;
674         case NET_DEVICE_ETHERNET:
675                 __net_add_profile_ethernet(&ethernet_profiles, &ethernet_cnt);
676                 *profile_cnt += ethernet_cnt;
677         default:
678                 break;
679         }
680
681         if (*profile_cnt) {
682                 profiles = g_try_new0(net_profile_info_t, *profile_cnt);
683                 if (profiles) {
684                         *profile_list = profiles;
685                         if (cellular_cnt > 0) {
686                                 memcpy(profiles, cellular_profiles,
687                                         sizeof(net_profile_info_t) * cellular_cnt);
688                                 profiles += cellular_cnt;
689                         }
690
691                         if (wifi_cnt > 0) {
692                                 memcpy(profiles, wifi_profiles,
693                                         sizeof(net_profile_info_t) * wifi_cnt);
694                                 profiles += wifi_cnt;
695                         }
696
697                         if (ethernet_cnt > 0) {
698                                 memcpy(profiles, ethernet_profiles,
699                                         sizeof(net_profile_info_t) * ethernet_cnt);
700                                 profiles += ethernet_cnt;
701                         }
702                 }
703         }
704
705         return NET_ERR_NONE;
706 }
707
708 API int net_get_all_profile_list(void *handle, net_profile_info_t **profile_list, int *profile_cnt)
709 {
710         int cellular_cnt = 0;
711         int wifi_cnt = 0;
712         int ethernet_cnt = 0;
713         net_profile_info_t *cellular_profiles = NULL;
714         net_profile_info_t *wifi_profiles = NULL;
715         net_profile_info_t *ethernet_profiles = NULL;
716         net_profile_info_t *profiles = NULL;
717
718         *profile_cnt = 0;
719
720         __net_add_profile_cellular(&cellular_profiles, &cellular_cnt);
721         *profile_cnt += cellular_cnt;
722
723         __net_add_profile_wifi(&wifi_profiles, &wifi_cnt);
724         *profile_cnt += wifi_cnt;
725
726         __net_add_profile_ethernet(&ethernet_profiles, &ethernet_cnt);
727         *profile_cnt += ethernet_cnt;
728
729         if (*profile_cnt) {
730                 profiles = g_try_new0(net_profile_info_t, *profile_cnt);
731                 if (profiles) {
732                         *profile_list = profiles;
733                         if (cellular_cnt > 0) {
734                                 memcpy(profiles, cellular_profiles,
735                                         sizeof(net_profile_info_t) * cellular_cnt);
736                                 profiles += cellular_cnt;
737                         }
738
739                         if (wifi_cnt > 0) {
740                                 memcpy(profiles, wifi_profiles,
741                                         sizeof(net_profile_info_t) * wifi_cnt);
742                                 profiles += wifi_cnt;
743                         }
744
745                         if (ethernet_cnt > 0) {
746                                 memcpy(profiles, ethernet_profiles,
747                                         sizeof(net_profile_info_t) * ethernet_cnt);
748                                 profiles += ethernet_cnt;
749                         }
750                 }
751         }
752
753         return NET_ERR_NONE;
754 }
755
756 API int net_get_ethernet_cable_state(void *handle, int *state)
757 {
758         *state = 0;
759         return NET_ERR_NONE;
760 }
761
762 API int net_get_active_net_info(void *handle, net_profile_info_t *active_profile_info)
763 {
764         __net_add_default_profile_cellular(active_profile_info);
765
766         return NET_ERR_NONE;
767 }
768
769 API int net_add_profile(void *handle, net_service_type_t network_type, net_profile_info_t *prof_info)
770 {
771         return NET_ERR_NONE;
772 }
773
774 API int net_delete_profile(void *handle, const char *profile_name)
775 {
776         return NET_ERR_NONE;
777 }
778
779 API int net_modify_profile(void *handle, const char *profile_name, net_profile_info_t *prof_info)
780 {
781         return NET_ERR_NONE;
782 }
783
784 API int net_reset_profile(void *handle, int type, int sim_id)
785 {
786         return NET_ERR_NONE;
787 }
788
789 API int net_open_mesh_connection_with_profile(void *handle, const char *profile_name)
790 {
791         return NET_ERR_NONE;
792 }
793
794 API int net_open_connection_with_profile(void *handle, const char *profile_name)
795 {
796         return NET_ERR_NONE;
797 }
798
799 API int net_set_default_cellular_service_profile(void *handle, const char *profile_name)
800 {
801         return NET_ERR_NONE;
802 }
803
804 API int net_set_default_cellular_service_profile_async(void *handle, const char *profile_name)
805 {
806         return NET_ERR_NONE;
807 }
808
809 API int net_close_mesh_connection(void *handle, const char *profile_name)
810 {
811         return NET_ERR_NONE;
812 }
813
814 API int net_close_connection(void *handle, const char *profile_name)
815 {
816         return NET_ERR_NONE;
817 }
818
819 API int net_add_route(void *handle, const char *ip_addr, const char *interface, int address_family)
820 {
821         return NET_ERR_NONE;
822 }
823
824 API int net_remove_route(void *handle, const char *ip_addr, const char *interface, int address_family)
825 {
826         return NET_ERR_NONE;
827 }
828
829 API int net_add_route_ipv6(void *handle, const char *ip_addr,
830                 const char *interface, int address_family, const char *gateway)
831 {
832         return NET_ERR_NONE;
833 }
834
835 API int net_remove_route_ipv6(void *handle, const char *ip_addr,
836                 const char *interface, int address_family, const char *gateway)
837 {
838         return NET_ERR_NONE;
839 }
840
841 API int net_add_route_entry(void *handle, const char *ip_addr,
842                 const char *interface, int address_family, const char *gateway)
843 {
844         return NET_ERR_NONE;
845 }
846
847 API int net_remove_route_entry(void *handle, const char *ip_addr,
848                 const char *interface, int address_family, const char *gateway)
849 {
850         return NET_ERR_NONE;
851 }
852
853 API int net_set_statistics(void *handle, net_device_t device_type,
854                 net_statistics_type_e statistics_type)
855 {
856         return NET_ERR_NONE;
857 }
858
859 API int net_get_statistics(void *handle, net_device_t device_type,
860                 net_statistics_type_e statistics_type, unsigned long long *size)
861 {
862         *size = 1024;
863         return NET_ERR_NONE;
864 }
865
866 API int net_get_cellular_modem_object_path(char **modem_path, int sim_id)
867 {
868         *modem_path = g_strdup("/sprdmodem0");
869         return NET_ERR_NONE;
870 }
871
872 API int net_ethernet_eap_enable(gboolean enable, const char *profilename)
873 {
874         return NET_ERR_NONE;
875 }
876
877 API int net_ethernet_eap_supported(gboolean *supported)
878 {
879         *supported = TRUE;
880         return NET_ERR_NONE;
881 }
882
883 API int net_save_ethernet_eap_config(void *handle, net_dev_info_t *net_info)
884 {
885         return NET_ERR_NONE;
886 }
887
888 API int net_start_tcpdump(void *handle)
889 {
890         return NET_ERR_NONE;
891 }
892
893 API int net_stop_tcpdump(void *handle)
894 {
895         return NET_ERR_NONE;
896 }
897
898 API gboolean net_get_tcpdump_state(void *handle, gboolean *is_tcpdump_running)
899 {
900         *is_tcpdump_running = TRUE;
901         return NET_ERR_NONE;
902 }
903
904 API int net_mptcp_supported(void *handle, gboolean *support)
905 {
906         *support = TRUE;
907         return NET_ERR_NONE;
908 }
909
910 API int net_mptcp_set_enabled(void *handle, int enable)
911 {
912         return NET_ERR_NONE;
913 }
914
915 API int net_mptcp_get_enabled(void *handle, int *enable)
916 {
917         *enable = 1;
918         return NET_ERR_NONE;
919 }
920
921 API int net_mptcp_set_path_manager(void *handle, const char *pm)
922 {
923         return NET_ERR_NONE;
924 }
925
926 API int net_mptcp_get_path_manager(void *handle, char **pm)
927 {
928         *pm = g_strdup("default");
929         return NET_ERR_NONE;
930 }
931
932 API int net_mptcp_set_scheduler(void *handle, const char *scheduler)
933 {
934         return NET_ERR_NONE;
935 }
936
937 API int net_mptcp_get_scheduler(void *handle, char **scheduler)
938 {
939         *scheduler = g_strdup("default");
940         return NET_ERR_NONE;
941 }