github.com/rigado/snapd@v2.42.5-go-mod+incompatible/interfaces/builtin/gpio_control.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2019 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  // https://www.kernel.org/doc/Documentation/gpio/
    23  const gpioControlSummary = `allows control of all aspects of GPIO pins`
    24  
    25  // Controlling all aspects of GPIO pins can potentially impact other snaps and
    26  // grant wide access to specific hardware and the system, so treat as
    27  // super-privileged
    28  const gpioControlBaseDeclarationPlugs = `
    29    gpio-control:
    30      allow-installation: false
    31      deny-auto-connection: true
    32  `
    33  const gpioControlBaseDeclarationSlots = `
    34    gpio-control:
    35      allow-installation:
    36        slot-snap-type:
    37          - core
    38      deny-auto-connection: true
    39  `
    40  
    41  const gpioControlConnectedPlugAppArmor = `
    42  # Description: Allow controlling all aspects of GPIO pins. This can potentially
    43  # impact the system and other snaps, and allows privileged access to hardware.
    44  
    45  /sys/class/gpio/{,un}export rw,
    46  /sys/class/gpio/gpio[0-9]*/{active_low,direction,value,edge} rw,
    47  `
    48  
    49  func init() {
    50  	registerIface(&commonInterface{
    51  		name:                  "gpio-control",
    52  		summary:               gpioControlSummary,
    53  		implicitOnCore:        true,
    54  		implicitOnClassic:     true,
    55  		baseDeclarationPlugs:  gpioControlBaseDeclarationPlugs,
    56  		baseDeclarationSlots:  gpioControlBaseDeclarationSlots,
    57  		connectedPlugAppArmor: gpioControlConnectedPlugAppArmor,
    58  		reservedForOS:         true,
    59  	})
    60  }