diff options
author | davidevinavil <davidevinavil@gmail.com> | 2017-01-28 23:50:06 +0100 |
---|---|---|
committer | davidevinavil <davidevinavil@gmail.com> | 2017-01-29 00:43:48 +0100 |
commit | 6c1c200387e2cd7808ce674c6bed0aaf000b1c9f (patch) | |
tree | a452ff889331d1db24762a0869f014461c3ea0e3 | |
parent | 383eabacae4e4e74d32fd415c26db134964b2fb3 (diff) |
z2_plus: Fix mac address
* Let's ensure that wlan_mac.bin exists in persist partition and
is valid, otherwise WiFi MAC address is randomized on every boot
because qca_cld can't properly read it
Change-Id: I82d66b84104802eaa1becdc72a1aec5fd185e5fa
-rwxr-xr-x | device.mk | 1 | ||||
-rwxr-xr-x | rootdir/init.qcom.rc | 6 | ||||
-rw-r--r-- | sepolicy/file_contexts | 1 | ||||
-rw-r--r-- | sepolicy/readmac.te | 17 | ||||
-rw-r--r-- | wifi/Android.mk | 11 | ||||
-rw-r--r-- | wifi/zuk_readmac.c | 72 |
6 files changed, 108 insertions, 0 deletions
@@ -291,6 +291,7 @@ PRODUCT_PACKAGES += \ libQWiFiSoftApCfg \ libwpa_client \ hostapd \ + readmac \ dhcpcd.conf \ wpa_supplicant \ wpa_supplicant.conf diff --git a/rootdir/init.qcom.rc b/rootdir/init.qcom.rc index 2905309..14f4d73 100755 --- a/rootdir/init.qcom.rc +++ b/rootdir/init.qcom.rc @@ -612,6 +612,12 @@ on property:init.svc.zygote=running on property:init.svc.zygote=restarting stop ppd +service readmac /system/bin/readmac + class main + user root + group root + oneshot + service energy-awareness /system/bin/energy-awareness class main user root diff --git a/sepolicy/file_contexts b/sepolicy/file_contexts index affd4b0..65154cf 100644 --- a/sepolicy/file_contexts +++ b/sepolicy/file_contexts @@ -28,3 +28,4 @@ /sys/kernel/debug/rmt_storage/rmts u:object_r:debugfs_rmts:s0 /system/bin/ifaadaemon u:object_r:ifaadaemon_exec:s0 +/system/bin/readmac u:object_r:readmac_exec:s0 diff --git a/sepolicy/readmac.te b/sepolicy/readmac.te new file mode 100644 index 0000000..adb739e --- /dev/null +++ b/sepolicy/readmac.te @@ -0,0 +1,17 @@ +type readmac, domain; +type readmac_exec, exec_type, file_type; + +# Allow for transition from init domain to readmac +init_daemon_domain(readmac) + +# Allow readmac to communicate with qmuxd via qmux_radio socket +qmux_socket(readmac) + +# Allow readmac to fully access wlan_mac.bin persist file +allow readmac persist_file:dir rw_dir_perms; +allow readmac persist_file:file create_file_perms; + +allow readmac self:capability dac_override; +allow readmac self:socket create_socket_perms; + +allow readmac diag_device:chr_file rw_file_perms; diff --git a/wifi/Android.mk b/wifi/Android.mk new file mode 100644 index 0000000..8876a2b --- /dev/null +++ b/wifi/Android.mk @@ -0,0 +1,11 @@ +LOCAL_PATH:= $(call my-dir) + +ifeq ($(strip $(BOARD_HAS_QCOM_WLAN)),true) +include $(CLEAR_VARS) +LOCAL_MODULE := readmac +LOCAL_MODULE_TAGS := optional +LOCAL_SRC_FILES := zuk_readmac.c +LOCAL_CFLAGS += -Wall +LOCAL_SHARED_LIBRARIES := libc libcutils libutils liblog +include $(BUILD_EXECUTABLE) +endif 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; +} |