Wifi and bluetooth on snappy ubuntu on a dragonboard?

Hi,
name: dragonboard-kernel
version: null
version-script: |
. debian/debian.env
dpkg-parsechangelog -l $DEBIAN/changelog -S version
summary: The Canonical snapdragon arm64 kernel
description: The Canonical snapdragon arm64 kernel
grade: stable
confinement: strict
type: kernel

parts:
kernel:
plugin: kernel
source: .
source-type: git
kconfigflavour: snapdragon
kconfigs:
- CONFIG_DEBUG_INFO=n
kernel-image-target: Image
kernel-device-trees:
- qcom/apq8016-sbc
- qcom/msm8916-mtp

firmware:
plugin: tar-content
source: firmware.tar
destination: firmware
stage-packages:
- linux-firmware
organize:
lib/firmware: firmware
prime:
- -usr
- -lib
install: |
mkdir -p $SNAPCRAFT_PART_INSTALL/firmware/wlan
ln -s /run/macaddr0 $SNAPCRAFT_PART_INSTALL/firmware/wlan/
build-packages:
- cpio
- libssl-dev

now im building kernel snap by adding
kernel-image-target: Image

and earlier i got this error
unable to read/find dragonboard-kernel_x1.snap/dtbs/apq8016-sbc.dtb
so i modified to
kernel-device-trees:

  • qcom/apq8016-sbc

Now everything is working fine.even the earlier crash when connecting to network hasnt come up.

Thanks

1 Like

Hi ogra,
I want to toggle the states of wifi and Bluetooth. so i prepared script
wlan="$(grep -l “phy” /sys/class/rfkill/rfkill*/name)"
if [[ -f “$wlan” ]]; then
wlan_state="$(echo “$wlan” | sed ‘s/name$/state/’)"
fi

bt="$(grep -l “hci” /sys/class/rfkill/rfkill*/name)"
if [[ -f “$bt” ]]; then
bt_state="$(echo “$bt” | sed ‘s/name$/state/’)"
fi

rfkill_curr_state="$(cat $wlan_state)"

if [ “$rfkill_curr_state” == “1” ]; then
rfkill_new_state=0
else
rfkill_new_state=1
fi

echo $rfkill_new_state > $wlan_state
echo $rfkill_curr_state > $bt_state

Now i wanted to run this as a script or command/daemon which should continuously monitor the states of wlan and BT.
my question is how to write a snapcraft.yaml for it.
i went through snapcraft.io documentation and read all the info but im very much confused what to mention in apps and parts section since i’m very new to this.
kindly help me on this

Regards
laxman

First of all make it clean shell :wink: and drop the double [ and double ] as well as the == … It is good practice to make your code POSIX compatible instead of using bash specifics (especially since /bin/sh is not necessarily bash on all systems out there and since bash uses several megabytes of extra ram over most other shells (like /bin/dash as used in ubuntu))

Regarding your snapcraft.yaml, something like:

apps:
  toggle:
    command: myscript
    plugs: [network, network-control]

should theoretically work (after manually connecting the network-control interface). Practically, when i tried to test it i noticed bug 1707612 which actually prevents you from using this interface … (lets see what @jdstrand has to say …)

Hi ogra,
i built snap and installed it manually. But i didnt find any change in rfkill state before and after installing the snap.
how to validate the installed snap or script?

Thanks

well, even if it worked you’d most likely hit the same bug as i did … when you call your snapped command (indeed after manually connecting the network-control interface), are there any “DENIED” messages in syslog ?

Hi,
i didnt find any such bug.
below is my syslog
localhost systemd[1]: Mounting Mount unit for my-snap-name…
localhost systemd[1]: Mounted Mount unit for my-snap-name.
localhost /usr/lib/snapd/snapd[1245]: daemon.go:176: DEBUG: uid=1000;@ POST /v2/snaps/my-snap-name 95.602ms 202
localhost /usr/lib/snapd/snapd[1245]: taskrunner.go:367: DEBUG: Running task 153 on Do: Stop snap “my-snap-name” services
localhost /usr/lib/snapd/snapd[1245]: taskrunner.go:367: DEBUG: Running task 154 on Do: Remove aliases for snap “my-snap-name”
localhost /usr/lib/snapd/snapd[1245]: taskrunner.go:367: DEBUG: Running task 155 on Do: Make snap “my-snap-name” unavailable to the system
localhost /usr/lib/snapd/snapd[1245]: taskrunner.go:367: DEBUG: Running task 156 on Do: Remove security profile for snap “my-snap-name” (x1)
localhost /usr/lib/snapd/snapd[1245]: taskrunner.go:367: DEBUG: Running task 157 on Do: Remove data for snap “my-snap-name” (x1)
localhost /usr/lib/snapd/snapd[1245]: taskrunner.go:367: DEBUG: Running task 158 on Do: Remove snap “my-snap-name” (x1) from the system
localhost systemd[1]: Unmounted Mount unit for my-snap-name.
localhost /usr/lib/snapd/snapd[1245]: taskrunner.go:367: DEBUG: Running task 159 on Do: Discard interface connections for snap “my-snap-name” (x1)
localhost /usr/lib/snapd/snapd[1245]: taskrunner.go:367: DEBUG: Running task 161 on Do: Mount snap “my-snap-name” (unset)
localhost systemd[1]: Mounting Mount unit for my-snap-name…
localhost systemd[1]: Mounted Mount unit for my-snap-name.
localhost /usr/lib/snapd/snapd[1245]: taskrunner.go:367: DEBUG: Running task 162 on Do: Copy snap “my-snap-name” data
localhost /usr/lib/snapd/snapd[1245]: taskrunner.go:367: DEBUG: Running task 163 on Do: Setup snap “my-snap-name” (unset) security profiles
localhost kernel: [ 302.029584] audit: type=1400 audit(1501503359.133:33): apparmor=“STATUS” operation=“profile_replace” profile=“unconfined” name=“snap.my-snap-name.toggle” pid=1836 comm=“apparmor_parser”
localhost /usr/lib/snapd/snapd[1245]: taskrunner.go:367: DEBUG: Running task 164 on Do: Make snap “my-snap-name” (unset) available to the system
localhost /usr/lib/snapd/snapd[1245]: taskrunner.go:367: DEBUG: Running task 165 on Do: Setup snap “my-snap-name” (unset) security profiles (phase 2)
localhost /usr/lib/snapd/snapd[1245]: taskrunner.go:367: DEBUG: Running task 166 on Do: Set automatic aliases for snap “my-snap-name”
localhost /usr/lib/snapd/snapd[1245]: taskrunner.go:367: DEBUG: Running task 167 on Do: Setup snap “my-snap-name” aliases
localhost /usr/lib/snapd/snapd[1245]: taskrunner.go:367: DEBUG: Running task 168 on Do: Start snap “my-snap-name” (unset) services
localhost /usr/lib/snapd/snapd[1245]: taskrunner.go:367: DEBUG: Running task 169 on Do: Run configure hook of “my-snap-name” snap if present
684:Jul 31 12:16:01 localhost /usr/lib/snapd/snapd[1245]: daemon.go:176: DEBUG: uid=0;@ GET /v2/snaps?snaps=my-snap-name 5.175ms 200

that log obviously only shows the install process … did you also run the snapped app ?

Hi,
when i try to run using
laxman1234@localhost:~$ snap run toggle-rf-states
error: cannot find app “toggle-rf-states” in “toggle-rf-states”

snap info returned
commands:

  • toggle-rf-states.toggle

if i run toggle-rf-states.toggle im getting error as below
/snap/toggle-rf-states/x1/command-toggle.wrapper: 4: exec: /snap/toggle-rf-states/x1/…/toggle.sh: not found.

is anything wrong with my snapcraft.yaml?
apps:
toggle:
command: …/toggle.sh
plugs: [network, network-control]

parts:
toggle:
source: .
plugin: nil

what do you expect this to do ? (hint: it does nothing)

try something like:

parts:
  toggle:
    source: .
    plugin: dump
    organize:
      myscript: usr/bin/myscript

Hi,
i made the above change then if i run
$sudo toggle-rf-states.toggle
grep: /sys/class/rfkill/rfkill0/name: Permission denied
grep: /sys/class/rfkill/rfkill1/name: Permission denied
/snap/toggle-rf-states/x1/toggle: 3: /snap/toggle-rf-states/x1/toggle.sh: [[: not found
grep: /sys/class/rfkill/rfkill0/name: Permission denied
grep: /sys/class/rfkill/rfkill1/name: Permission denied
/snap/toggle-rf-states/x1/toggle: 8: /snap/toggle-rf-states/x1/toggle.sh: [[: not found

and i’m pretty sure you will find corresponding apparmor denials in syslog for this …

(the other “[[: not found” is related to the bash specific code as i said above)

ya,
ul 31 13:24:04 localhost /usr/lib/snapd/snapd[1245]: daemon.go:176: DEBUG: uid=1000;@ GET /v2/snaps/toggle-rf-states 5.167ms 200
Jul 31 13:24:26 localhost kernel: [ 4409.805772] audit: type=1400 audit(1501507466.917:54): apparmor=“DENIED” operation=“open” profile=“snap.toggle-rf-states.toggle” name="/sys/devices/virtual/bluetooth/hci0/rfkill0/name" pid=3468 comm=“grep” requested_mask=“r” denied_mask=“r” fsuid=1000 ouid=0
Jul 31 13:24:26 localhost kernel: [ 4409.806819] audit: type=1400 audit(1501507466.917:55): apparmor=“DENIED” operation=“open” profile=“snap.toggle-rf-states.toggle” name="/sys/devices/platform/wcn36xx/ieee80211/phy0/rfkill1/name" pid=3468 comm=“grep” requested_mask=“r” denied_mask=“r” fsuid=1000 ouid=0

1 Like

Can you add to /var/lib/snapd/apparmor/profiles/snap.toggle-rf-states.toggle before the final ‘}’ the following:

/sys/devices/{pci[0-9]*,platform,virtual}/**/rfkill[0-9]*/{,*} r,

Then load the updated policy into the kernel with:

$ sudo apparmor_parser -r /var/lib/snapd/apparmor/profiles/snap.toggle-rf-states.toggle

and report back if you have any security denials?

(I’ve already submitted the above to an existing PR and a future release of snapd will have the update)

Actually, this is what I’ve submitted:

/sys/class/rfkill/ r,                                                           
/sys/devices/{pci[0-9]*,platform,virtual}/**/rfkill[0-9]*/{,**} r,

Hi,
i made above mentioned change then observed below log.
/snap/toggle-rf-states/x1/toggle.sh: 11: /snap/toggle-rf-states/x1/toggle.sh: 1: not found
/snap/toggle-rf-states/x1/toggle.sh: 18: /snap/toggle-rf-states/x1/toggle.sh: cannot create /sys/class/rfkill/rfkill1/state: Permission denied
/snap/toggle-rf-states/x1/toggle.sh: 19: /snap/toggle-rf-states/x1/toggle.sh: cannot create /sys/class/rfkill/rfkill0/state: Permission denied

So the reading from /sys/class/rfkill/rfkill0/name now works, but writing to the state file does not … i guess thats a second apparmor rule needed …

I’ve added this to the PR:

/sys/devices/{pci[0-9]*,platform,virtual}/**/rfkill[0-9]*/state w,

please comment if this addresses the issue.