[Feature][ZXW-452]merge P54U02 version

Only Configure: No
Affected branch: master
Affected module: unknow
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update: No

Change-Id: I17e6795ab66e2b9d1cbbfec4b7c0028d666e177d
diff --git a/ap/lib/libsoftap/netapi.c b/ap/lib/libsoftap/netapi.c
index 7b47c06..91e3892 100755
--- a/ap/lib/libsoftap/netapi.c
+++ b/ap/lib/libsoftap/netapi.c
@@ -590,4 +590,48 @@
 
 }
 
+/*
+ * ether_to_eui64 - Convert 48-bit Ethernet address into 64-bit EUI
+ *
+ * convert the 48-bit MAC address of eth0 into EUI 64. caller also assumes
+ * that the system has a properly configured Ethernet interface for this
+ * function to return non-zero.
+ */
+int netapi_ether_to_eui64(const char *dev_name, netapi_eui64_t *p_eui64)
+{
+    struct ifreq ifr;
+    int skfd;
+    const unsigned char *ptr;
+
+    skfd = socket(PF_INET6, SOCK_DGRAM, 0);
+    if(skfd == -1)
+    {
+        slog(NET_PRINT, SLOG_ERR, "eui64 open IPv6 socket fail");
+        return 0;
+    }
+
+    strcpy(ifr.ifr_name, dev_name);
+    if(ioctl(skfd, SIOCGIFHWADDR, &ifr) < 0)
+    {
+        close(skfd);
+        slog(NET_PRINT, SLOG_ERR, "eui64 obtain hardware address for %s fail", dev_name);
+        return 0;
+    }
+    close(skfd);
+
+    /*
+     * And convert the EUI-48 into EUI-64, per RFC 2472 [sec 4.1]
+     */
+    ptr = ifr.ifr_hwaddr.sa_data;
+    p_eui64->e8[0] = ptr[0] | 0x02;
+    p_eui64->e8[1] = ptr[1];
+    p_eui64->e8[2] = ptr[2];
+    p_eui64->e8[3] = 0xFF;
+    p_eui64->e8[4] = 0xFE;
+    p_eui64->e8[5] = ptr[3];
+    p_eui64->e8[6] = ptr[4];
+    p_eui64->e8[7] = ptr[5];
+
+    return 1;
+}