db845c: Set Ethernet MAC address on boot am: 7cc6a2d9d7
Change-Id: I7a4bcc9f89a1bb1c4d8045dfd0f4d213e75fb510
diff --git a/db845c/device.mk b/db845c/device.mk
index cc5b973..b37e06f 100644
--- a/db845c/device.mk
+++ b/db845c/device.mk
@@ -43,5 +43,10 @@
PRODUCT_COPY_FILES += \
device/linaro/dragonboard/qcom/init.qcom.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.qcom.rc
+# Install scripts to set Ethernet MAC address
+PRODUCT_COPY_FILES += \
+ $(LOCAL_PATH)/eth_mac_addr.rc:/system/etc/init/eth_mac_addr.rc \
+ $(LOCAL_PATH)/eth_mac_addr.sh:/system/bin/eth_mac_addr.sh
+
# Copy firmware files
$(call inherit-product-if-exists, $(LOCAL_PATH)/firmware/device.mk)
diff --git a/db845c/eth_mac_addr.rc b/db845c/eth_mac_addr.rc
new file mode 100644
index 0000000..e710c19
--- /dev/null
+++ b/db845c/eth_mac_addr.rc
@@ -0,0 +1,9 @@
+service eth_mac_addr /system/bin/eth_mac_addr.sh
+ class core
+ user root
+ group system
+ disabled
+ oneshot
+
+on post-fs-data
+ start eth_mac_addr
diff --git a/db845c/eth_mac_addr.sh b/db845c/eth_mac_addr.sh
new file mode 100644
index 0000000..bdc1ba7
--- /dev/null
+++ b/db845c/eth_mac_addr.sh
@@ -0,0 +1,15 @@
+#! /system/bin/sh
+# Set eth0 mac address.
+#
+# Get the unique board serial number from /proc/cmdline,
+# prepend '0's to the serial number to fill 5 LSBs of the
+# MAC address and prepend "02" as MSB to prepare a 6 byte
+# locally administered unicast MAC address.
+# Format the output in xx:xx:xx:xx:xx:xx format for the
+# "ip" set address command to work.
+
+SERIALNO=`cat /proc/cmdline | grep -o serialno.* | cut -f2 -d'=' | awk '{printf("02%010s\n", $1)}' | sed 's/\(..\)/\1:/g' | sed '$s/:$//'`
+
+/system/bin/ip link set dev eth0 down
+/system/bin/ip link set dev eth0 address "${SERIALNO}"
+/system/bin/ip link set dev eth0 up
diff --git a/sepolicy/eth_mac_addr.te b/sepolicy/eth_mac_addr.te
new file mode 100644
index 0000000..d2e4e1a
--- /dev/null
+++ b/sepolicy/eth_mac_addr.te
@@ -0,0 +1,12 @@
+type eth_mac_addr, domain, coredomain;
+type eth_mac_addr_exec, exec_type, system_file_type, file_type;
+init_daemon_domain(eth_mac_addr);
+
+allow eth_mac_addr proc_cmdline:file { open read };
+allow eth_mac_addr rootfs:dir { open read };
+allow eth_mac_addr self:capability net_admin;
+allow eth_mac_addr self:netlink_route_socket { bind create getattr nlmsg_readpriv nlmsg_write read setopt write };
+allow eth_mac_addr self:udp_socket { create ioctl };
+allow eth_mac_addr shell_exec:file { execute getattr map read };
+allow eth_mac_addr system_file:file execute_no_trans;
+allow eth_mac_addr toolbox_exec:file { execute execute_no_trans getattr map open read };
diff --git a/sepolicy/file_contexts b/sepolicy/file_contexts
index 165f3b3..247e1ab 100644
--- a/sepolicy/file_contexts
+++ b/sepolicy/file_contexts
@@ -29,6 +29,8 @@
/data/vendor/readwrite(/.*)? u:object_r:tqftpserv_vendor_data_file:s0
/data/vendor/readonly(/.*)? u:object_r:tqftpserv_vendor_data_file:s0
+/system/bin/eth_mac_addr\.sh u:object_r:eth_mac_addr_exec:s0
+
/vendor/bin/hw/android\.hardware\.gatekeeper@1\.0-service\.software u:object_r:hal_gatekeeper_default_exec:s0
/vendor/bin/pd-mapper u:object_r:pd_mapper_exec:s0
/vendor/bin/qrtr-cfg u:object_r:qrtr_exec:s0