From 709acc6b3848dfdbd712178ea755c37ed34ae992 Mon Sep 17 00:00:00 2001 From: Igor Pecovnik Date: Sat, 29 Oct 2016 08:27:02 +0200 Subject: [PATCH] Added BT service to Nano Pi AIR, enabled by default, random MAC at start --- extras/tools.sh | 3 ++- scripts/ap6212 | 11 +++++++++++ scripts/ap6212-bluetooth | 26 +++++++++++++++++++++++--- scripts/firstrun | 11 +++++++---- 4 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 scripts/ap6212 diff --git a/extras/tools.sh b/extras/tools.sh index 99232cf5d..f586fdf24 100644 --- a/extras/tools.sh +++ b/extras/tools.sh @@ -50,7 +50,8 @@ compile_tools() install -m 644 $SRC/lib/scripts/brcm40183 $tmpdir/armbian-tools-${RELEASE}_${REVISION}_${ARCH}/etc/default install -m 755 $SRC/lib/scripts/brcm40183-patch $tmpdir/armbian-tools-${RELEASE}_${REVISION}_${ARCH}/etc/init.d - # ap6212 BT + # ap6212 configs and service + install -m 644 $SRC/lib/scripts/ap6212 $tmpdir/armbian-tools-${RELEASE}_${REVISION}_${ARCH}/etc/default install -m 755 $SRC/lib/scripts/ap6212-bluetooth $tmpdir/armbian-tools-${RELEASE}_${REVISION}_${ARCH}/etc/init.d cd $tmpdir/armbian-tools-${RELEASE}_${REVISION}_${ARCH} diff --git a/scripts/ap6212 b/scripts/ap6212 new file mode 100644 index 000000000..e87d5d8b0 --- /dev/null +++ b/scripts/ap6212 @@ -0,0 +1,11 @@ +# +# Default it is called to be uncertain wich MAC address the chipset has. +# Therefore it is recommendable to set the MAC address manually. +# This can be done by setting the variable MAC_ADDR with a chosen value. +# If this variable is empty or not set the default 11:22:33:44:55:66 will be chosen. + +MAC_ADDR=43:29:B1:55:01:01 + +# + +PORT=ttyS1 diff --git a/scripts/ap6212-bluetooth b/scripts/ap6212-bluetooth index b7af5b651..d4078a4ed 100644 --- a/scripts/ap6212-bluetooth +++ b/scripts/ap6212-bluetooth @@ -10,6 +10,14 @@ # Description: Patch firmware for ap6212 adapter ### END INIT INFO +DEFAULTS="/etc/default/ap6212" + +# Include ap6212 defaults if available +if [ -r "${DEFAULTS}" ] +then + . "${DEFAULTS}" +fi + # exit if bluetooth utils are not installed [ -f "/bin/hciconfig" ] || exit 0 @@ -30,12 +38,24 @@ then echo "ap6212 BT device allready initialized" hcitool dev else - # Start patching + # Select MAC address + if [ -z "$MAC_ADDR" ]; then + MAC_OPTIONS="11:22:33:44:55:66" + else + MAC_OPTIONS="$MAC_ADDR" + fi + # Select tty port + if [ -z "$PORT" ]; then + log_warning_msg "No PORT set in /etc/default/ap6212, will use ttyS1" + PORT="ttyS1" + fi + + # Start patching rfkill unblock all echo "0" > /sys/class/rfkill/rfkill0/state echo "1" > /sys/class/rfkill/rfkill0/state - echo " " > /dev/ttyS1 - hciattach /dev/ttyS1 bcm43xx 115200 + echo " " > /dev/$PORT + hciattach /dev/$PORT bcm43xx 115200 flow bdaddr $MAC_OPTIONS hciconfig hci0 up fi } diff --git a/scripts/firstrun b/scripts/firstrun index 7b699fe44..d7cad549f 100644 --- a/scripts/firstrun +++ b/scripts/firstrun @@ -86,7 +86,7 @@ collect_information() { [[ "$BOARD" == "cubietruck" ]] && update-rc.d brcm40183-patch defaults # enable BT on Banana M2+ - [[ "$BOARD" == "bananapim2plus" ]] && update-rc.d ap6212-bluetooth defaults + [[ "$BOARD" == "bananapim2plus" || "$BOARD" == "nanopiair" ]] && update-rc.d ap6212-bluetooth defaults # enable BT on Solidrun boards [[ "$BOARD" == "Cubox i2eX/i4" ]] && update-rc.d brcm4330-patch defaults && /etc/init.d/brcm4330-patch start @@ -114,14 +114,17 @@ collect_information() { adjust_sunxi_settings() { # set some mac address for BT - [[ "$(lsmod | grep bcmdhd)" != "" ]] && \ + [[ "$(lsmod | grep dhd)" != "" ]] && \ (MACADDR=$(printf '43:29:B1:%02X:%02X:%02X\n' $[RANDOM%256] $[RANDOM%256] $[RANDOM%256]) ; \ - sed -i "s/^MAC_ADDR=.*/MAC_ADDR=${MACADDR}/" /etc/default/brcm40183 \ + sed -i "s/^MAC_ADDR=.*/MAC_ADDR=${MACADDR}/" /etc/default/brcm40183 ;\ + sed -i "s/^MAC_ADDR=.*/MAC_ADDR=${MACADDR}/" /etc/default/ap6212 \ echo -e "\n### [firstrun] Use MAC address ${MACADDR} for Bluetooth from now" >>${Log}) - # relink /etc/network/interfaces on OPi Lite and NanoPi Air + # change serial port for BT on NanoPi Air + # relink /etc/network/interfaces on OPi Lite and NanoPi Air case ${BOARD_NAME} in "NanoPi Air"|"Orange Pi Lite") + sed -i "s/^PORT=.*/PORT=ttyS3/" /etc/default/ap6212 cd /etc/network/ && ln -sf interfaces.network-manager interfaces ;; esac