From 72da964f9aee60263e9195a27fcbe7e1037a1571 Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Mon, 8 Jul 2019 15:47:03 +0200 Subject: [PATCH] sm8350-common: Add wifi mac generator shell script Change-Id: I95593db840dc4a668f899d248b2c8e03d4ebbc3e --- common.mk | 1 + sepolicy/vendor/file_contexts | 1 + sepolicy/vendor/wifi-mac-generator.te | 12 +++++++ wifi-mac-generator/Android.mk | 9 +++++ wifi-mac-generator/wifi-mac-generator.rc | 9 +++++ wifi-mac-generator/wifi-mac-generator.sh | 43 ++++++++++++++++++++++++ 6 files changed, 75 insertions(+) create mode 100644 sepolicy/vendor/wifi-mac-generator.te create mode 100644 wifi-mac-generator/Android.mk create mode 100644 wifi-mac-generator/wifi-mac-generator.rc create mode 100644 wifi-mac-generator/wifi-mac-generator.sh diff --git a/common.mk b/common.mk index fc8cbaf..2d8391f 100644 --- a/common.mk +++ b/common.mk @@ -520,6 +520,7 @@ PRODUCT_PACKAGES += \ vendor.qti.hardware.wifi.hostapd@1.2.vendor \ vendor.qti.hardware.wifi.supplicant@2.0.vendor \ vendor.qti.hardware.wifi.supplicant@2.1.vendor \ + wifi-mac-generator \ WifiResCommon \ wpa_supplicant \ wpa_supplicant.conf diff --git a/sepolicy/vendor/file_contexts b/sepolicy/vendor/file_contexts index 3922254..7adb95a 100644 --- a/sepolicy/vendor/file_contexts +++ b/sepolicy/vendor/file_contexts @@ -1,6 +1,7 @@ # Binaries /(vendor|system/vendor)/bin/opf-service u:object_r:opf_exec:s0 /(vendor|system/vendor)/bin/tri-state-key_daemon u:object_r:tri-state-key_daemon_exec:s0 +/(vendor|system/vendor)/bin/wifi-mac-generator u:object_r:wifi-mac-generator_exec:s0 /(vendor|system/vendor)/bin/wlchgd u:object_r:wlchgd_exec:s0 # Block devices diff --git a/sepolicy/vendor/wifi-mac-generator.te b/sepolicy/vendor/wifi-mac-generator.te new file mode 100644 index 0000000..ced7309 --- /dev/null +++ b/sepolicy/vendor/wifi-mac-generator.te @@ -0,0 +1,12 @@ +type wifi-mac-generator, domain; +type wifi-mac-generator_exec, exec_type, vendor_file_type, file_type; + +init_daemon_domain(wifi-mac-generator) + +allow wifi-mac-generator vendor_shell_exec:file rx_file_perms; +allow wifi-mac-generator vendor_toolbox_exec:file rx_file_perms; + +r_dir_file(wifi-mac-generator, vendor_data_file) + +allow wifi-mac-generator mnt_vendor_file:dir search; +allow wifi-mac-generator mnt_vendor_file:file w_file_perms; diff --git a/wifi-mac-generator/Android.mk b/wifi-mac-generator/Android.mk new file mode 100644 index 0000000..164a3c3 --- /dev/null +++ b/wifi-mac-generator/Android.mk @@ -0,0 +1,9 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := wifi-mac-generator +LOCAL_MODULE_CLASS := ETC +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_EXECUTABLES) +LOCAL_SRC_FILES := wifi-mac-generator.sh +LOCAL_INIT_RC := wifi-mac-generator.rc +include $(BUILD_PREBUILT) diff --git a/wifi-mac-generator/wifi-mac-generator.rc b/wifi-mac-generator/wifi-mac-generator.rc new file mode 100644 index 0000000..0defe7f --- /dev/null +++ b/wifi-mac-generator/wifi-mac-generator.rc @@ -0,0 +1,9 @@ +service vendor.wifi-mac-generator /vendor/bin/wifi-mac-generator + class main + user wifi + group wifi + oneshot + disabled + +on post-fs-data + start vendor.wifi-mac-generator diff --git a/wifi-mac-generator/wifi-mac-generator.sh b/wifi-mac-generator/wifi-mac-generator.sh new file mode 100644 index 0000000..0bf4878 --- /dev/null +++ b/wifi-mac-generator/wifi-mac-generator.sh @@ -0,0 +1,43 @@ +#!/vendor/bin/sh +WLAN_MAC_VENDOR_PREFIX="C0EEFB" +WLAN_MAC_PERSIST_PATH="/mnt/vendor/persist/wlan_mac.bin" + +function wait_for_file() { + retries=0 + + while [ ! -f "${1}" ]; do + retries=$((retries + 1)) + + if [ "${retries}" -eq 10 ]; then + return 1 + fi + + sleep 1 + done + + return 0 +} + +if [[ ! -f "${WLAN_MAC_PERSIST_PATH}" ]] || [[ ! -s "${WLAN_MAC_PERSIST_PATH}" ]]; then + MAC_0_PATH="/data/vendor/oemnvitems/4678_0" + + if ! wait_for_file "${MAC_0_PATH}"; then + MAC_0="${WLAN_MAC_VENDOR_PREFIX}`xxd -l 3 -p /dev/urandom | tr '[:lower:]' '[:upper:]'`" + else + MAC_0=`xxd -p "${MAC_0_PATH}" | tr '[:lower:]' '[:upper:]'` + fi + + MAC_1_PATH="/data/vendor/oemnvitems/4678_1" + + if ! wait_for_file "${MAC_1_PATH}"; then + MAC_1="${WLAN_MAC_VENDOR_PREFIX}`xxd -l 3 -p /dev/urandom | tr '[:lower:]' '[:upper:]'`" + else + MAC_1=`xxd -p "${MAC_1_PATH}" | tr '[:lower:]' '[:upper:]'` + fi + + echo "Intf0MacAddress=${MAC_0}" > "${WLAN_MAC_PERSIST_PATH}" + echo "Intf1MacAddress=${MAC_1}" >> "${WLAN_MAC_PERSIST_PATH}" + echo "Intf2MacAddress=000AF58989FD" >> "${WLAN_MAC_PERSIST_PATH}" + echo "Intf3MacAddress=000AF58989FC" >> "${WLAN_MAC_PERSIST_PATH}" + echo "END" >> "${WLAN_MAC_PERSIST_PATH}" +fi