github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/interfaces/builtin/sd_control.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2021 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package builtin 21 22 import ( 23 "github.com/snapcore/snapd/interfaces" 24 "github.com/snapcore/snapd/interfaces/apparmor" 25 "github.com/snapcore/snapd/interfaces/udev" 26 ) 27 28 const sdControlSummary = `allows controlling SD cards on certain boards` 29 30 const sdControlBaseDeclarationSlots = ` 31 sd-control: 32 allow-installation: 33 slot-snap-type: 34 - core 35 deny-auto-connection: true 36 ` 37 38 const sdControlBaseDeclarationPlugs = ` 39 sd-control: 40 allow-installation: false 41 deny-auto-connection: true 42 ` 43 44 const dualSDSDControlConnectedPlugApparmor = ` 45 # Description: can manage and control the SD cards using the DualSD driver. 46 47 # The main DualSD device node is used to control certain aspects of SD cards on 48 # the system. 49 /dev/DualSD rw, 50 ` 51 52 var dualSDSDControlConnectedPlugUDev = []string{ 53 `KERNEL=="DualSD"`, 54 } 55 56 type sdControlInterface struct { 57 commonInterface 58 } 59 60 func (iface *sdControlInterface) AppArmorConnectedPlug(spec *apparmor.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error { 61 // check the flavor of the plug 62 63 var flavor string 64 _ = plug.Attr("flavor", &flavor) 65 switch flavor { 66 // only supported flavor for now 67 case "dual-sd": 68 spec.AddSnippet(dualSDSDControlConnectedPlugApparmor) 69 } 70 71 return nil 72 } 73 74 func (iface *sdControlInterface) UDevConnectedPlug(spec *udev.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error { 75 // check the flavor of the plug 76 var flavor string 77 _ = plug.Attr("flavor", &flavor) 78 switch flavor { 79 // only supported flavor for now 80 case "dual-sd": 81 for _, rule := range dualSDSDControlConnectedPlugUDev { 82 spec.TagDevice(rule) 83 } 84 } 85 86 return nil 87 } 88 89 func init() { 90 registerIface(&sdControlInterface{commonInterface{ 91 name: "sd-control", 92 summary: sdControlSummary, 93 baseDeclarationSlots: sdControlBaseDeclarationSlots, 94 baseDeclarationPlugs: sdControlBaseDeclarationPlugs, 95 implicitOnCore: true, 96 implicitOnClassic: true, 97 }}) 98 }