#!/usr/bin/env ash # This script provides helper functions for blue-merle UNICAST_MAC_GEN () { loc_mac_numgen=`python3 -c "import random; print(f'{random.randint(0,2**48) & 0b111111101111111111111111111111111111111111111111:0x}'.zfill(12))"` loc_mac_formatted=$(echo "$loc_mac_numgen" | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4:\5:\6/') echo "$loc_mac_formatted" } # randomize BSSID RESET_BSSIDS () { uci set wireless.@wifi-iface[1].macaddr=`UNICAST_MAC_GEN` uci set wireless.@wifi-iface[0].macaddr=`UNICAST_MAC_GEN` uci commit wireless # you need to reset wifi for changes to apply, i.e. executing "wifi" } # This chaneges the MAC address clients see when connecting to the WiFi spawned by the device. # You can check with "arp -a" that your endpoint, e.g. your laptop, sees a different MAC after a reboot of the Mudi. RANDOMIZE_MACADDR () { uci set network.@device[1].macaddr=`UNICAST_MAC_GEN` uci commit network # You need to restart the network, i.e. /etc/init.d/network restart } READ_IMEI () { local answer=1 while [[ "$answer" -eq 1 ]]; do local imei=$(gl_modem AT AT+GSN | grep -w -E "[0-9]{14,15}") if [[ $? -eq 1 ]]; then echo -n "Failed to read IMEI. Try again? (Y/n): " read answer case $answer in n*) answer=0;; N*) answer=0;; *) answer=1;; esac if [[ $answer -eq 0 ]]; then exit 1 fi else answer=0 fi done echo $imei } READ_IMSI () { local answer=1 while [[ "$answer" -eq 1 ]]; do local imsi=$(gl_modem AT AT+CIMI | grep -w -E "[0-9]{6,15}") if [[ $? -eq 1 ]]; then echo -n "Failed to read IMSI. Try again? (Y/n): " read answer case $answer in n*) answer=0;; N*) answer=0;; *) answer=1;; esac if [[ $answer -eq 0 ]]; then exit 1 fi else answer=0 fi done echo $imsi } CHECK_ABORT () { sim_change_switch=`cat /tmp/sim_change_switch` if [[ "$sim_change_switch" = "off" ]]; then echo '{ "msg": "SIM change aborted." }' > /dev/ttyS0 sleep 1 exit 1 fi }