#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <vconf/vconf.h>
#include <system_info.h>
#include "net_connection_private.h"
static GSList *conn_handle_list = NULL;
-static int tv_profile = -1; // Unknown
//LCOV_EXCL_START
static int __connection_convert_net_state(int status)
rv = _connection_libnet_init(*connection);
if (rv == NET_ERR_ACCESS_DENIED) {
CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
- g_free(*connection);
- *connection = NULL;
-
+ g_free(*connection); //LCOV_EXCL_LINE
+ *connection = NULL; //LCOV_EXCL_LINE
CONN_UNLOCK; //LCOV_EXCL_LINE
return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
} else if (rv != NET_ERR_NONE) {
CONNECTION_LOG(CONNECTION_ERROR, "Failed to create connection[%d]", rv); //LCOV_EXCL_LINE
- g_free(*connection);
- *connection = NULL;
-
+ g_free(*connection); //LCOV_EXCL_LINE
+ *connection = NULL; //LCOV_EXCL_LINE
CONN_UNLOCK; //LCOV_EXCL_LINE
return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
}
EXPORT_API int connection_get_mac_address(connection_h connection, connection_type_e type, char** mac_addr)
{
- FILE *fp;
+ FILE *fp = NULL;
char buf[CONNECTION_MAC_INFO_LENGTH + 1];
CONN_LOCK;
switch (type) {
case CONNECTION_TYPE_WIFI:
- if (__builtin_expect(tv_profile == -1, 0)) {
- char *profileName;
- system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
- if (*profileName == 't' || *profileName == 'T')
- tv_profile = 1; //LCOV_EXCL_LINE
- else
- tv_profile = 0;
- free(profileName);
- }
- if (tv_profile == 1) {
- //LCOV_EXCL_START
+ if (access(WIFI_MAC_INFO_FILE, F_OK) == 0)
fp = fopen(WIFI_MAC_INFO_FILE, "r");
- if (fp == NULL) {
- CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", WIFI_MAC_INFO_FILE);
- CONN_UNLOCK;
- return CONNECTION_ERROR_OUT_OF_MEMORY;
- }
+ if (fp) {
if (fgets(buf, sizeof(buf), fp) == NULL) {
CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", WIFI_MAC_INFO_FILE);
fclose(fp);
CONNECTION_LOG(CONNECTION_INFO, "%s : %s", WIFI_MAC_INFO_FILE, buf);
- *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
- if (*mac_addr == NULL) {
- CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
- fclose(fp);
- CONN_UNLOCK;
- return CONNECTION_ERROR_OUT_OF_MEMORY;
- }
- g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
+ *mac_addr = g_strdup(buf);
fclose(fp);
- //LCOV_EXCL_STOP
} else {
*mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
CONN_UNLOCK; //LCOV_EXCL_LINE
return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
}
+
+ if (strlen(*mac_addr) == 0) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Mac address is invalid"
+ " from %s", VCONFKEY_WIFI_BSSID_ADDRESS); //LCOV_EXCL_LINE
+ g_free(*mac_addr); //LCOV_EXCL_LINE
+ *mac_addr = NULL; //LCOV_EXCL_LINE
+ CONN_UNLOCK; //LCOV_EXCL_LINE
+ return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+ }
}
break;
//LCOV_EXCL_START
CONNECTION_LOG(CONNECTION_INFO, "%s : %s", ETHERNET_MAC_INFO_FILE, buf);
- *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
- if (*mac_addr == NULL) {
- CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
- fclose(fp);
- CONN_UNLOCK;
- return CONNECTION_ERROR_OUT_OF_MEMORY;
- }
-
- g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
+ *mac_addr = g_strdup(buf);
fclose(fp);
-
break;
//LCOV_EXCL_STOP
default:
_connection_libnet_set_cellular_subscriber_id(profile, default_subscriber_id);
}
-static void __profile_init_wifi_profile(net_profile_info_t *profile_info)
+static int __profile_init_wifi_profile(net_profile_info_t *profile_info)
{
+ GSList *list = NULL;
+ GSList *interface_list = NULL;
+
+ if (net_get_wifi_interface_list(NULL, &interface_list) != NET_ERR_NONE) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Fail to get interface list");
+ return CONNECTION_ERROR_OPERATION_FAILED;
+ }
+
+ for (list = interface_list; list; list = list->next) {
+ const char *interface_name = list->data;
+ g_strlcpy(profile_info->ProfileName, interface_name, NET_PROFILE_NAME_LEN_MAX);
+ g_strlcpy(profile_info->ProfileInfo.Wlan.net_info.ProfileName,
+ interface_name, NET_PROFILE_NAME_LEN_MAX);
+ break;
+ }
+
+ if (list == NULL) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Fail to get interface name");
+ g_slist_free_full(interface_list, g_free);
+ return CONNECTION_ERROR_INVALID_OPERATION;
+ }
+
profile_info->profile_type = NET_DEVICE_WIFI;
profile_info->ProfileState = NET_STATE_TYPE_IDLE;
profile_info->ProfileInfo.Wlan.net_info.IpConfigType = NET_IP_CONFIG_TYPE_OFF;
profile_info->ProfileInfo.Wlan.wlan_mode = NETPM_WLAN_CONNMODE_AUTO;
profile_info->ProfileInfo.Wlan.security_info.sec_mode = WLAN_SEC_MODE_NONE;
profile_info->ProfileInfo.Wlan.security_info.enc_mode = WLAN_ENC_MODE_NONE;
+
+ g_slist_free_full(interface_list, g_free);
+ return CONNECTION_ERROR_NONE;
}
//LCOV_EXCL_START
-static char* __profile_get_ethernet_proxy(void)
+static char *__profile_get_ethernet_proxy(void)
{
char *proxy;
}
__profile_init_cellular_profile(profile_info, keyword);
} else if (type == CONNECTION_PROFILE_TYPE_WIFI) {
- __profile_init_wifi_profile(profile_info);
+ rv = __profile_init_wifi_profile(profile_info);
+ if (rv != CONNECTION_ERROR_NONE) {
+ g_free(profile_info);
+ CONN_UNLOCK;
+ return rv;
+ }
}
*profile = (connection_profile_h)profile_info;