+EXPORT_API int connection_get_mac_address(connection_h connection, connection_type_e type, char** mac_addr)
+{
+ FILE *fp;
+ char buf[CONNECTION_MAC_INFO_LENGTH + 1];
+
+ CHECK_FEATURE_SUPPORTED(WIFI_FEATURE, ETHERNET_FEATURE);
+
+ if (type == CONNECTION_TYPE_WIFI)
+ CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+ else if (type == CONNECTION_TYPE_ETHERNET) //LCOV_EXCL_LINE
+ CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE); //LCOV_EXCL_LINE
+
+ if (mac_addr == NULL || !(__connection_check_handle_validity(connection))) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ 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;
+ else
+ tv_profile = 0;
+ free(profileName);
+ }
+ if (tv_profile == 1) {
+ fp = fopen(WIFI_MAC_INFO_FILE, "r");
+ if (fp == NULL) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", WIFI_MAC_INFO_FILE); //LCOV_EXCL_LINE
+ return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
+ }
+
+ if (fgets(buf, sizeof(buf), fp) == NULL) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", WIFI_MAC_INFO_FILE); //LCOV_EXCL_LINE
+ fclose(fp); //LCOV_EXCL_LINE
+ return CONNECTION_ERROR_OPERATION_FAILED;
+ }
+
+ 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"); //LCOV_EXCL_LINE
+ fclose(fp); //LCOV_EXCL_LINE
+ return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
+ }
+ g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
+ fclose(fp);
+ } else {
+ *mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
+
+ if (*mac_addr == NULL) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Failed to get vconf from %s", VCONFKEY_WIFI_BSSID_ADDRESS); //LCOV_EXCL_LINE
+ return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+ }
+ }
+ break;
+ //LCOV_EXCL_START
+ case CONNECTION_TYPE_ETHERNET:
+ fp = fopen(ETHERNET_MAC_INFO_FILE, "r");
+ if (fp == NULL) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", ETHERNET_MAC_INFO_FILE);
+ return CONNECTION_ERROR_OUT_OF_MEMORY;
+ }
+
+ if (fgets(buf, sizeof(buf), fp) == NULL) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", ETHERNET_MAC_INFO_FILE);
+ fclose(fp);
+ return CONNECTION_ERROR_OPERATION_FAILED;
+ }
+
+ 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);
+ return CONNECTION_ERROR_OUT_OF_MEMORY;
+ }
+
+ g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
+ fclose(fp);
+
+ break;
+ //LCOV_EXCL_STOP
+ default:
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
+ return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+ }
+
+ /* Checking Invalid MAC Address */
+ if ((strcmp(*mac_addr, "00:00:00:00:00:00") == 0) ||
+ (strcmp(*mac_addr, "ff:ff:ff:ff:ff:ff") == 0)) {
+ CONNECTION_LOG(CONNECTION_ERROR, "MAC Address(%s) is invalid", *mac_addr); //LCOV_EXCL_LINE
+ return CONNECTION_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
+ }
+
+ CONNECTION_LOG(CONNECTION_INFO, "MAC Address %s", *mac_addr);
+
+ return CONNECTION_ERROR_NONE;
+}
+
+
+EXPORT_API int connection_is_metered_network(connection_h connection, bool* is_metered)
+{
+ CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
+
+ if (is_metered == NULL || !(__connection_check_handle_validity(connection))) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ int rv = _connection_libnet_get_metered_state(is_metered);
+ if (rv != CONNECTION_ERROR_NONE) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Fail to get metered state[%d]", rv); //LCOV_EXCL_LINE
+ return rv; //LCOV_EXCL_LINE
+ }
+
+ CONNECTION_LOG(CONNECTION_INFO, "metered state: %s", is_metered ? "true" : "false");
+ return CONNECTION_ERROR_NONE;
+}
+
+