+ return last_err;
+}
+
+int __connman_device_request_scan(enum connman_service_type type)
+{
+ return connman_device_request_scan(type, false);
+}
+
+int __connman_device_request_scan_full(enum connman_service_type type)
+{
+ return connman_device_request_scan(type, true);
+}
+
+int __connman_device_request_hidden_scan(struct connman_device *device,
+ const char *ssid, unsigned int ssid_len,
+ const char *identity, const char *passphrase,
+ const char *security, void *user_data)
+{
+ struct connman_device_scan_params params;
+
+ DBG("device %p", device);
+
+ if (!device || !device->driver ||
+ !device->driver->scan)
+ return -EINVAL;
+
+ params.type = CONNMAN_SERVICE_TYPE_UNKNOWN;
+ params.ssid = ssid;
+ params.ssid_len = ssid_len;
+ params.identity = identity;
+ params.passphrase = passphrase;
+ params.security = security;
+ params.user_data = user_data;
+
+ return device->driver->scan(device, ¶ms);
+}
+
+void __connman_device_stop_scan(enum connman_service_type type)
+{
+ GSList *list;
+
+ for (list = device_list; list; list = list->next) {
+ struct connman_device *device = list->data;
+
+ if (!device_has_service_type(device, type))
+ continue;
+
+ if (device->driver && device->driver->stop_scan)
+ device->driver->stop_scan(type, device);
+ }
+}
+
+#if defined TIZEN_EXT
+#define WIFI_MAC "/opt/etc/.mac.info"
+#define MAC_ADDR_LEN 18
+
+char *_get_wifi_addr(void)
+{
+ FILE *fp = NULL;
+ char* rv = 0;
+ char wifi_mac[MAC_ADDR_LEN + 1];
+ char *str;
+
+ fp = fopen(WIFI_MAC, "r");
+ if (!fp){
+ connman_error("[%s] not present", WIFI_MAC);
+ return NULL;
+ }
+
+ rv = fgets(wifi_mac, MAC_ADDR_LEN, fp);
+ if (!rv) {
+ connman_error("Failed to get wifi mac address");
+ fclose(fp);
+ return NULL;
+ }
+
+ str = g_try_malloc0(MAC_ADDR_LEN);
+ if (!str) {
+ connman_error("memory allocation failed");
+ fclose(fp);
+ return NULL;
+ }
+
+ snprintf(str, MAC_ADDR_LEN, "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c",
+ g_ascii_tolower(wifi_mac[0]), g_ascii_tolower(wifi_mac[1]),
+ g_ascii_tolower(wifi_mac[3]), g_ascii_tolower(wifi_mac[4]),
+ g_ascii_tolower(wifi_mac[6]), g_ascii_tolower(wifi_mac[7]),
+ g_ascii_tolower(wifi_mac[9]), g_ascii_tolower(wifi_mac[10]),
+ g_ascii_tolower(wifi_mac[12]), g_ascii_tolower(wifi_mac[13]),
+ g_ascii_tolower(wifi_mac[15]), g_ascii_tolower(wifi_mac[16]));
+ fclose(fp);
+ return str;
+}
+
+char *_get_wifi_ident(void)
+{
+ FILE *fp = NULL;
+ char* rv = 0;
+ char wifi_mac[MAC_ADDR_LEN + 1];
+ char *str;
+
+ fp = fopen(WIFI_MAC, "r");
+ if (!fp){
+ connman_error("[%s] not present", WIFI_MAC);
+ return NULL;
+ }
+
+ rv = fgets(wifi_mac, MAC_ADDR_LEN, fp);
+ if (!rv) {
+ connman_error("Failed to get wifi mac address");
+ fclose(fp);
+ return NULL;
+ }
+
+ str = g_try_malloc0(MAC_ADDR_LEN);
+ if (!str) {
+ connman_error("memory allocation failed");
+ fclose(fp);
+ return NULL;
+ }
+
+ snprintf(str, MAC_ADDR_LEN, "%c%c%c%c%c%c%c%c%c%c%c%c",
+ g_ascii_tolower(wifi_mac[0]), g_ascii_tolower(wifi_mac[1]),
+ g_ascii_tolower(wifi_mac[3]), g_ascii_tolower(wifi_mac[4]),
+ g_ascii_tolower(wifi_mac[6]), g_ascii_tolower(wifi_mac[7]),
+ g_ascii_tolower(wifi_mac[9]), g_ascii_tolower(wifi_mac[10]),
+ g_ascii_tolower(wifi_mac[12]), g_ascii_tolower(wifi_mac[13]),
+ g_ascii_tolower(wifi_mac[15]), g_ascii_tolower(wifi_mac[16]));
+ fclose(fp);
+ return str;
+}
+#endif
+
+#if defined TIZEN_EXT
+char *index2ident(int index, const char *prefix)
+#else
+static char *index2ident(int index, const char *prefix)
+#endif
+{
+ struct ifreq ifr;
+ struct ether_addr eth;
+ char *str;
+ int sk, err, len;
+
+ if (index < 0)
+ return NULL;
+
+ sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+ if (sk < 0)
+ return NULL;
+
+ memset(&ifr, 0, sizeof(ifr));
+ ifr.ifr_ifindex = index;
+
+ err = ioctl(sk, SIOCGIFNAME, &ifr);
+
+ if (err == 0)
+ err = ioctl(sk, SIOCGIFHWADDR, &ifr);
+
+ close(sk);
+
+ if (err < 0)
+ return NULL;
+
+ len = prefix ? strlen(prefix) + 18 : 18;
+
+ str = g_malloc(len);
+ if (!str)
+ return NULL;
+
+ memcpy(ð, &ifr.ifr_hwaddr.sa_data, sizeof(eth));
+ snprintf(str, len, "%s%02x%02x%02x%02x%02x%02x",
+ prefix ? prefix : "",
+ eth.ether_addr_octet[0],
+ eth.ether_addr_octet[1],
+ eth.ether_addr_octet[2],
+ eth.ether_addr_octet[3],
+ eth.ether_addr_octet[4],
+ eth.ether_addr_octet[5]);
+
+ return str;
+}
+
+#if defined TIZEN_EXT
+char *index2addr(int index)
+#else
+static char *index2addr(int index)
+#endif
+{
+ struct ifreq ifr;
+ struct ether_addr eth;
+ char *str;
+ int sk, err;
+
+ if (index < 0)
+ return NULL;
+
+ sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+ if (sk < 0)
+ return NULL;
+
+ memset(&ifr, 0, sizeof(ifr));
+ ifr.ifr_ifindex = index;
+
+ err = ioctl(sk, SIOCGIFNAME, &ifr);
+
+ if (err == 0)
+ err = ioctl(sk, SIOCGIFHWADDR, &ifr);
+
+ close(sk);
+
+ if (err < 0)
+ return NULL;
+
+ str = g_malloc(18);
+ if (!str)
+ return NULL;
+
+ memcpy(ð, &ifr.ifr_hwaddr.sa_data, sizeof(eth));
+ snprintf(str, 18, "%02X:%02X:%02X:%02X:%02X:%02X",
+ eth.ether_addr_octet[0],
+ eth.ether_addr_octet[1],
+ eth.ether_addr_octet[2],
+ eth.ether_addr_octet[3],
+ eth.ether_addr_octet[4],
+ eth.ether_addr_octet[5]);
+
+ return str;
+}
+
+struct connman_device *connman_device_create_from_index(int index)
+{
+ enum connman_device_type type;
+ struct connman_device *device;
+ char *devname, *ident = NULL;
+ char *addr = NULL, *name = NULL;
+
+ if (index < 0)
+ return NULL;
+
+ devname = connman_inet_ifname(index);
+ if (!devname)
+ return NULL;
+
+ if (__connman_device_isfiltered(devname)) {
+ connman_info("Ignoring interface %s (filtered)", devname);
+ g_free(devname);
+ return NULL;
+ }
+
+ type = __connman_rtnl_get_device_type(index);
+
+ switch (type) {
+ case CONNMAN_DEVICE_TYPE_UNKNOWN:
+ connman_info("Ignoring interface %s (type unknown)", devname);
+ g_free(devname);
+ return NULL;
+ case CONNMAN_DEVICE_TYPE_ETHERNET:
+ case CONNMAN_DEVICE_TYPE_GADGET:
+ case CONNMAN_DEVICE_TYPE_WIFI:
+ name = index2ident(index, "");
+ addr = index2addr(index);
+ break;
+ case CONNMAN_DEVICE_TYPE_BLUETOOTH:
+ case CONNMAN_DEVICE_TYPE_CELLULAR:
+ case CONNMAN_DEVICE_TYPE_GPS:
+ case CONNMAN_DEVICE_TYPE_VENDOR:
+ name = g_strdup(devname);
+ break;
+ }
+
+ device = connman_device_create(name, type);
+ if (!device)