2 // Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <system_info.h>
24 #include <arpa/inet.h>
25 #include <vconf/vconf.h>
27 #include "net_connection_private.h"
30 #define API __attribute__ ((visibility("default")))
33 struct cellular_profile_s {
36 net_state_type_t state;
37 net_state_type_t state6;
40 net_ip_config_type_t ipv4_method;
44 net_ip_config_type_t ipv6_method;
45 net_service_type_t service_type;
53 } cellular_profile[] = {
55 "/net/connman/service/cellular_sprdmodem0_45005_534b2054656c65636f6d_1164_1",
56 "534b2054656c65636f6d_1164_1",
61 NET_IP_CONFIG_TYPE_FIXED,
76 "/net/connman/service/cellular_sprdmodem0_45005_534b2054656c65636f6d_1165_2",
77 "534b2054656c65636f6d_1165_2",
89 "lteoma.nate.com:9093",
90 "http://omms.nate.com:9082/oma_mms",
98 struct wifi_profile_s {
100 wlan_security_mode_type_t sec_mode;
101 wlan_encryption_mode_type_t enc_mode;
103 unsigned char strength;
104 char essid[NET_WLAN_ESSID_LEN + 1];
105 char bssid[NET_MAX_MAC_ADDR_LEN + 1];
107 unsigned int frequency;
108 unsigned int keymgmt;
109 net_state_type_t state;
110 net_state_type_t state6;
113 net_ip_config_type_t ipv4_method;
117 net_ip_config_type_t ipv6_method;
120 "/net/connman/service/wifi_f8d11162c728_4e4554474541523839_managed_psk",
121 WLAN_SEC_MODE_WPA2_PSK,
130 NET_STATE_TYPE_READY,
131 NET_STATE_TYPE_CONFIGURATION,
134 NET_IP_CONFIG_TYPE_DYNAMIC,
138 NET_IP_CONFIG_TYPE_AUTO_IP,
141 "/net/connman/service/wifi_f8d11162c728_545431_managed_psk",
142 WLAN_SEC_MODE_WPA2_PSK,
155 NET_IP_CONFIG_TYPE_DYNAMIC,
159 NET_IP_CONFIG_TYPE_AUTO_IP,
163 struct ethernet_profile_s {
165 net_state_type_t state;
166 net_state_type_t state6;
169 net_ip_config_type_t ipv4_method;
173 net_ip_config_type_t ipv6_method;
174 } ethernet_profile[] = {
176 "/net/connman/service/ethernet_dca632888ceb_cable",
177 NET_STATE_TYPE_READY,
178 NET_STATE_TYPE_CONFIGURATION,
181 NET_IP_CONFIG_TYPE_AUTO_IP,
185 NET_IP_CONFIG_TYPE_AUTO_IP,
190 API int system_info_get_platform_bool(const char *key, bool *value)
193 return SYSTEM_INFO_ERROR_NONE;
196 API int system_info_get_platform_string(const char *key, char **value)
198 if (g_strcmp0(key, "http://tizen.org/feature/profile") == 0)
199 *value = g_strdup("m");
201 return SYSTEM_INFO_ERROR_NONE;
205 API char *vconf_get_str(const char *in_key)
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");
219 API int vconf_get_int(const char *in_key, int *intval)
221 if (g_strcmp0(in_key, VCONFKEY_NETWORK_STATUS) == 0)
223 else if (g_strcmp0(in_key, VCONFKEY_NETWORK_CELLULAR_STATE) == 0)
225 else if (g_strcmp0(in_key, VCONF_TELEPHONY_DEFAULT_DATA_SERVICE) == 0)
227 else if (g_strcmp0(in_key, VCONFKEY_DNET_STATE) == 0)
229 else if (g_strcmp0(in_key, VCONFKEY_DNET_STATE2) == 0)
231 else if (g_strcmp0(in_key, VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT) == 0)
233 else if (g_strcmp0(in_key, VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV) == 0)
235 else if (g_strcmp0(in_key, VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT) == 0)
237 else if (g_strcmp0(in_key, VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV) == 0)
239 else if (g_strcmp0(in_key, VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2) == 0)
241 else if (g_strcmp0(in_key, VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2) == 0)
243 else if (g_strcmp0(in_key, VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT2) == 0)
245 else if (g_strcmp0(in_key, VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV2) == 0)
252 API int net_check_profile_privilege(void)
257 API int net_check_get_privilege(void)
262 API int net_check_set_privilege(void)
267 API int net_register_client(void **handle, net_event_cb_t event_cb, void *user_data)
272 API void net_deregister_client(void *handle)
277 API int net_get_metered_state(void *handle, int *state)
283 API int net_get_wifi_state(void *handle, net_wifi_state_t *current_state)
285 *current_state = WIFI_CONNECTED;
289 API int net_get_wifi_interface_list(void *handle, GSList **interface_list)
291 *interface_list = g_slist_append(*interface_list,
292 g_strdup("dummy_ifname"));
296 static void __net_init_profile_info(net_device_t profile_type, net_profile_info_t *ProfInfo)
299 net_dev_info_t *net_info = NULL;
301 memset(ProfInfo, 0, sizeof(net_profile_info_t));
302 ProfInfo->Favourite = (char)FALSE;
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;
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;
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;
342 net_info = &(ProfInfo->ProfileInfo.Mesh.net_info);
345 if (net_info != NULL) {
346 net_info->DnsCount = 0;
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;
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;
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);
374 net_info->ProxyMethod = NET_PROXY_TYPE_UNKNOWN;
378 static void __net_extract_ip(char *ip, net_addr_t *ipAddr)
380 unsigned char *ipValue = NULL;
381 char *saveptr = NULL;
382 char ipString[NETPM_IPV4_STR_LEN_MAX+1];
385 ipValue = (unsigned char *)&(ipAddr->Data.Ipv4.s_addr);
387 g_strlcpy(ipString, ip, NETPM_IPV4_STR_LEN_MAX+1);
389 ipToken[0] = strtok_r(ipString, ".", &saveptr);
391 if (ipToken[0] != NULL) {
392 ipToken[1] = strtok_r(NULL, ".", &saveptr);
394 if (ipToken[1] != NULL) {
395 ipToken[2] = strtok_r(NULL, ".", &saveptr);
397 if (ipToken[2] != NULL) {
398 ipToken[3] = strtok_r(NULL, ".", &saveptr);
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]);
411 static int __net_get_prefix_len(char *netmask)
413 in_addr_t mask = inet_network(netmask);
416 for (; mask; mask <<= 1)
422 static void __net_add_profile_cellular(net_profile_info_t **profile_info, int *profile_count)
425 net_profile_info_t *ProfilePtr = NULL;
426 int prof_cnt = sizeof(cellular_profile) / sizeof(struct cellular_profile_s);
428 for (i = 0; i < prof_cnt; ++i) {
429 net_profile_info_t ProfInfo = { 0, };
430 memset(&ProfInfo, 0, sizeof(net_profile_info_t));
432 __net_init_profile_info(NET_DEVICE_CELLULAR, &ProfInfo);
434 ProfInfo.profile_type = NET_DEVICE_CELLULAR;
435 g_strlcpy(ProfInfo.ProfileName, cellular_profile[i].obj, NET_PROFILE_NAME_LEN_MAX);
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;
444 net_dev_info_t *net_info = &(ProfInfo.ProfileInfo.Pdp.net_info);
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;
459 if (cellular_profile[i].ipv4_gateway) {
460 __net_extract_ip(cellular_profile[i].ipv4_gateway, &net_info->GatewayAddr);
461 net_info->BDefGateway = TRUE;
463 if (cellular_profile[i].ipv6_method)
464 net_info->IpConfigType6 = cellular_profile[i].ipv6_method;
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);
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;
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));
485 *profile_count = prof_cnt;
486 *profile_info = ProfilePtr;
489 static void __net_add_default_profile_cellular(net_profile_info_t *ProfInfo)
491 __net_init_profile_info(NET_DEVICE_CELLULAR, ProfInfo);
493 ProfInfo->profile_type = NET_DEVICE_CELLULAR;
494 g_strlcpy(ProfInfo->ProfileName, cellular_profile[0].obj, NET_PROFILE_NAME_LEN_MAX);
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;
503 net_dev_info_t *net_info = &(ProfInfo->ProfileInfo.Pdp.net_info);
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;
518 if (cellular_profile[0].ipv4_gateway) {
519 __net_extract_ip(cellular_profile[0].ipv4_gateway, &net_info->GatewayAddr);
520 net_info->BDefGateway = TRUE;
522 if (cellular_profile[0].ipv6_method)
523 net_info->IpConfigType6 = cellular_profile[0].ipv6_method;
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);
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;
541 static void __net_add_profile_wifi(net_profile_info_t **profile_info, int *profile_count)
544 net_profile_info_t *ProfilePtr = NULL;
545 int prof_cnt = sizeof(wifi_profile) / sizeof(struct wifi_profile_s);
547 for (i = 0; i < prof_cnt; ++i) {
548 net_profile_info_t ProfInfo = { 0, };
549 memset(&ProfInfo, 0, sizeof(net_profile_info_t));
551 __net_init_profile_info(NET_DEVICE_WIFI, &ProfInfo);
553 ProfInfo.profile_type = NET_DEVICE_WIFI;
554 g_strlcpy(ProfInfo.ProfileName, wifi_profile[i].obj, NET_PROFILE_NAME_LEN_MAX);
556 ProfInfo.ProfileState = wifi_profile[i].state;
557 ProfInfo.ProfileState6 = wifi_profile[i].state6;
559 net_wifi_profile_info_t *Wlan = &(ProfInfo.ProfileInfo.Wlan);
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;
574 net_dev_info_t *net_info = &(ProfInfo.ProfileInfo.Wlan.net_info);
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;
589 if (wifi_profile[i].ipv4_gateway) {
590 __net_extract_ip(wifi_profile[i].ipv4_gateway, &net_info->GatewayAddr);
591 net_info->BDefGateway = TRUE;
593 if (wifi_profile[i].ipv6_method)
594 net_info->IpConfigType6 = wifi_profile[i].ipv6_method;
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));
600 *profile_count = prof_cnt;
601 *profile_info = ProfilePtr;
604 static void __net_add_profile_ethernet(net_profile_info_t **profile_info, int *profile_count)
607 net_profile_info_t *ProfilePtr = NULL;
608 int prof_cnt = sizeof(ethernet_profile) / sizeof(struct ethernet_profile_s);
610 for (i = 0; i < prof_cnt; ++i) {
611 net_profile_info_t ProfInfo = { 0, };
612 memset(&ProfInfo, 0, sizeof(net_profile_info_t));
614 __net_init_profile_info(NET_DEVICE_ETHERNET, &ProfInfo);
616 ProfInfo.profile_type = NET_DEVICE_ETHERNET;
617 g_strlcpy(ProfInfo.ProfileName, ethernet_profile[i].obj, NET_PROFILE_NAME_LEN_MAX);
619 ProfInfo.ProfileState = ethernet_profile[i].state;
620 ProfInfo.ProfileState6 = ethernet_profile[i].state6;
622 net_dev_info_t *net_info = &(ProfInfo.ProfileInfo.Wlan.net_info);
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;
637 if (ethernet_profile[i].ipv4_gateway) {
638 __net_extract_ip(ethernet_profile[i].ipv4_gateway, &net_info->GatewayAddr);
639 net_info->BDefGateway = TRUE;
641 if (ethernet_profile[i].ipv6_method)
642 net_info->IpConfigType6 = ethernet_profile[i].ipv6_method;
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));
648 *profile_count = prof_cnt;
649 *profile_info = ProfilePtr;
652 API int net_get_profile_list(void *handle, net_device_t device_type,
653 net_profile_info_t **profile_list, int *profile_cnt)
655 int cellular_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;
665 switch (device_type) {
666 case NET_DEVICE_CELLULAR:
667 __net_add_profile_cellular(&cellular_profiles, &cellular_cnt);
668 *profile_cnt += cellular_cnt;
670 case NET_DEVICE_WIFI:
671 __net_add_profile_wifi(&wifi_profiles, &wifi_cnt);
672 *profile_cnt += wifi_cnt;
674 case NET_DEVICE_ETHERNET:
675 __net_add_profile_ethernet(ðernet_profiles, ðernet_cnt);
676 *profile_cnt += ethernet_cnt;
682 profiles = g_try_new0(net_profile_info_t, *profile_cnt);
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;
692 memcpy(profiles, wifi_profiles,
693 sizeof(net_profile_info_t) * wifi_cnt);
694 profiles += wifi_cnt;
697 if (ethernet_cnt > 0) {
698 memcpy(profiles, ethernet_profiles,
699 sizeof(net_profile_info_t) * ethernet_cnt);
700 profiles += ethernet_cnt;
708 API int net_get_all_profile_list(void *handle, net_profile_info_t **profile_list, int *profile_cnt)
710 int cellular_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;
720 __net_add_profile_cellular(&cellular_profiles, &cellular_cnt);
721 *profile_cnt += cellular_cnt;
723 __net_add_profile_wifi(&wifi_profiles, &wifi_cnt);
724 *profile_cnt += wifi_cnt;
726 __net_add_profile_ethernet(ðernet_profiles, ðernet_cnt);
727 *profile_cnt += ethernet_cnt;
730 profiles = g_try_new0(net_profile_info_t, *profile_cnt);
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;
740 memcpy(profiles, wifi_profiles,
741 sizeof(net_profile_info_t) * wifi_cnt);
742 profiles += wifi_cnt;
745 if (ethernet_cnt > 0) {
746 memcpy(profiles, ethernet_profiles,
747 sizeof(net_profile_info_t) * ethernet_cnt);
748 profiles += ethernet_cnt;
756 API int net_get_ethernet_cable_state(void *handle, int *state)
762 API int net_get_active_net_info(void *handle, net_profile_info_t *active_profile_info)
764 __net_add_default_profile_cellular(active_profile_info);
769 API int net_add_profile(void *handle, net_service_type_t network_type, net_profile_info_t *prof_info)
774 API int net_delete_profile(void *handle, const char *profile_name)
779 API int net_modify_profile(void *handle, const char *profile_name, net_profile_info_t *prof_info)
784 API int net_reset_profile(void *handle, int type, int sim_id)
789 API int net_open_mesh_connection_with_profile(void *handle, const char *profile_name)
794 API int net_open_connection_with_profile(void *handle, const char *profile_name)
799 API int net_set_default_cellular_service_profile(void *handle, const char *profile_name)
804 API int net_set_default_cellular_service_profile_async(void *handle, const char *profile_name)
809 API int net_close_mesh_connection(void *handle, const char *profile_name)
814 API int net_close_connection(void *handle, const char *profile_name)
819 API int net_add_route(void *handle, const char *ip_addr, const char *interface, int address_family)
824 API int net_remove_route(void *handle, const char *ip_addr, const char *interface, int address_family)
829 API int net_add_route_ipv6(void *handle, const char *ip_addr,
830 const char *interface, int address_family, const char *gateway)
835 API int net_remove_route_ipv6(void *handle, const char *ip_addr,
836 const char *interface, int address_family, const char *gateway)
841 API int net_add_route_entry(void *handle, const char *ip_addr,
842 const char *interface, int address_family, const char *gateway)
847 API int net_remove_route_entry(void *handle, const char *ip_addr,
848 const char *interface, int address_family, const char *gateway)
853 API int net_set_statistics(void *handle, net_device_t device_type,
854 net_statistics_type_e statistics_type)
859 API int net_get_statistics(void *handle, net_device_t device_type,
860 net_statistics_type_e statistics_type, unsigned long long *size)
866 API int net_get_cellular_modem_object_path(char **modem_path, int sim_id)
868 *modem_path = g_strdup("/sprdmodem0");
872 API int net_ethernet_eap_enable(gboolean enable, const char *profilename)
877 API int net_ethernet_eap_supported(gboolean *supported)
883 API int net_save_ethernet_eap_config(void *handle, net_dev_info_t *net_info)
888 API int net_start_tcpdump(void *handle)
893 API int net_stop_tcpdump(void *handle)
898 API gboolean net_get_tcpdump_state(void *handle, gboolean *is_tcpdump_running)
900 *is_tcpdump_running = TRUE;
904 API int net_mptcp_supported(void *handle, gboolean *support)
910 API int net_mptcp_set_enabled(void *handle, int enable)
915 API int net_mptcp_get_enabled(void *handle, int *enable)
921 API int net_mptcp_set_path_manager(void *handle, const char *pm)
926 API int net_mptcp_get_path_manager(void *handle, char **pm)
928 *pm = g_strdup("default");
932 API int net_mptcp_set_scheduler(void *handle, const char *scheduler)
937 API int net_mptcp_get_scheduler(void *handle, char **scheduler)
939 *scheduler = g_strdup("default");