aboutsummaryrefslogtreecommitdiff
path: root/wifi/zuk_readmac.c
diff options
context:
space:
mode:
authordavidevinavil <davidevinavil@gmail.com>2017-06-30 18:43:50 +0200
committerdavidevinavil <davidevinavil@gmail.com>2017-06-30 18:43:50 +0200
commit22248bae361aa743a4e8e045425c431f13b0966d (patch)
treee7364295bf7eee9f019a26a3f50bc2be9de3a813 /wifi/zuk_readmac.c
parent63ef7705757b4578736a91686569c03c2007a3ec (diff)
z2_plus: Move readmac in proper place
Diffstat (limited to 'wifi/zuk_readmac.c')
-rw-r--r--wifi/zuk_readmac.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/wifi/zuk_readmac.c b/wifi/zuk_readmac.c
new file mode 100644
index 0000000..55616d8
--- /dev/null
+++ b/wifi/zuk_readmac.c
@@ -0,0 +1,72 @@
+#define LOG_TAG "zuk_readmac"
+#define LOG_NDEBUG 0
+
+#include <cutils/log.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+
+#define MAC_ADDR_SIZE 6
+#define WLAN_MAC_BIN "/persist/wlan_mac.bin"
+
+static int check_wlan_mac_bin_file()
+{
+ char content[1024];
+ FILE *fp;
+
+ fp = fopen(WLAN_MAC_BIN, "r");
+ if (fp != NULL) {
+ memset(content, 0, sizeof(content));
+ fread(content, 1, sizeof(content)-1, fp);
+ fclose(fp);
+
+ if (strstr(content, "Intf0MacAddress") == NULL) {
+ ALOGV("%s is missing Intf0MacAddress entry value", WLAN_MAC_BIN);
+ return 1;
+ }
+
+ if (strstr(content, "Intf1MacAddress") == NULL) {
+ ALOGV("%s is missing Intf1MacAddress entry value", WLAN_MAC_BIN);
+ return 1;
+ }
+
+ return 0;
+ }
+ return 1;
+}
+
+int main()
+{
+ int i, wlan_addr3, wlan_addr4, wlan_addr5, ret;
+
+ // First 6 hex number are fix
+ unsigned char wlan_addr[] = { 0xd8, 0x9a, 0x34 };
+
+ // Last 6 hex number are random
+ srand(time(NULL) + getpid());
+ for (i = 0; i < 3; i++) {
+ wlan_addr3 = rand() % 256;
+ wlan_addr4 = rand() % 256;
+ wlan_addr5 = rand() % 256;
+ }
+
+ FILE *fp;
+
+ // Store WLAN MAC address in the persist file, if needed
+ if (check_wlan_mac_bin_file()) {
+ fp = fopen(WLAN_MAC_BIN, "w");
+ fprintf(fp, "Intf0MacAddress=%02X%02X%02X%02X%02X%02X\n",
+ wlan_addr[0], wlan_addr[1], wlan_addr[2], wlan_addr3, wlan_addr4, wlan_addr5);
+ fprintf(fp, "Intf1MacAddress=%02X%02X%02X%02X%02X%02X\n",
+ wlan_addr[0], wlan_addr[1], wlan_addr[2], wlan_addr3, wlan_addr4, (wlan_addr5+1));
+ fprintf(fp, "END\n");
+ fclose(fp);
+ ALOGV("%s was successfully generated", WLAN_MAC_BIN);
+ } else {
+ ALOGV("%s already exists and is valid", WLAN_MAC_BIN);
+ }
+
+ return 0;
+}