Add mac-address-set

This script sets mac address of wifi and bluetooth chip
according to serial number

Also add NetworkManager config to not use random mac address on wifi

BugzID: 54514
This commit is contained in:
Alexandre Bard 2019-03-29 11:43:48 +01:00
parent 60b1e7f14f
commit b968842975
5 changed files with 78 additions and 1 deletions

View File

@ -0,0 +1,11 @@
[Unit]
After=tibluetooth.service
[Service]
Type=oneshot
ExecStart=/usr/bin/mac-address-set
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,25 @@
#!/usr/bin/env bash
eth_mac=$(ip addr show eth0 | awk '$1 == "link/ether" {gsub(/\/.*$/, "", $2); print $2}')
wlan_mac=$(echo $eth_mac | sed -r "s/^(.{9})50(.{6})/\160\2/")
bt_addr=$(echo $eth_mac | sed -r "s/^(.{9})50(.{6})/\170\2/")
# Set WLAN address
ifconfig wlan0 | grep UP > /dev/null
up=$?
if [[ $up == 0 ]]; then
ifconfig wlan0 down
fi
ip link set wlan0 address $wlan_mac
if [[ $up == 0 ]]; then
ifconfig wlan0 up
fi
# Set BT address
bt_addr_rev=$(echo $bt_addr | sed -r "s/^(.{2}):(.{2}):(.{2}):(.{2}):(.{2}):(.{2})/\6:\5:\4:\3:\2:\1/")
bdaddr $bt_addr_rev
hciconfig hci0 reset
systemctl restart bluetooth

View File

@ -0,0 +1,35 @@
SUMMARY = "Set mac addresses of Wifi and bluetooth chips"
DESCRIPTION = "Small scripts that set the mac addresses based on ethernet mac"
AUTHOR = "Alexandre Bard"
LICENSE = "GPLv2+"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6"
PR = "r2"
inherit systemd
SRC_URI = " \
file://mac-address-set.service \
file://mac-address-set.sh \
"
S = "${WORKDIR}"
INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
SYSTEMD_SERVICE_${PN} = "mac-address-set.service"
SYSTEMD_AUTO_ENABLE ?= "enable"
FILES_${PN}_append = " \
/lib \
/usr \
"
do_install () {
install -d ${D}${systemd_unitdir}/system/
install -m 0644 mac-address-set.service ${D}${systemd_unitdir}/system/
install -d ${D}/usr/bin
install -m 0755 mac-address-set.sh ${D}/usr/bin/mac-address-set
}

View File

@ -0,0 +1,2 @@
[device]
wifi.scan-rand-mac-address=no

View File

@ -1,12 +1,16 @@
PACKAGECONFIG_append = " modemmanager bluez5" PACKAGECONFIG_append = " modemmanager bluez5"
FILESEXTRAPATHS_append := "${THISDIR}/${PN}" FILESEXTRAPATHS_append := "${THISDIR}/${PN}"
SRC_URI_append = " file://system-connections.tar.gz" SRC_URI_append = "\
file://system-connections.tar.gz \
file://NetworkManager.conf \
"
do_install_append() { do_install_append() {
rm -rf ${D}/run ${D}${localstatedir}/run rm -rf ${D}/run ${D}${localstatedir}/run
mkdir -p ${D}${sysconfdir}/NetworkManager/system-connections mkdir -p ${D}${sysconfdir}/NetworkManager/system-connections
install -m 0600 ${WORKDIR}/system-connections/* ${D}${sysconfdir}/NetworkManager/system-connections/ install -m 0600 ${WORKDIR}/system-connections/* ${D}${sysconfdir}/NetworkManager/system-connections/
install -m 0644 ${WORKDIR}/NetworkManager.conf ${D}${sysconfdir}/NetworkManager/
} }