Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 7e636a7
  • /
  • tools
  • /
  • crypto
  • /
  • ccp
  • /
  • dbc.py
Raw File Download
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:3f6a825ffc9e4e25e67d926f3ff0d4f8c3b8c369
directory badge Iframe embedding
swh:1:dir:78c12bb5e63ce1a9c6d11e395d27ff3b659b39ee
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
dbc.py
#!/usr/bin/python3
# SPDX-License-Identifier: GPL-2.0

import ctypes
import os

DBC_UID_SIZE = 16
DBC_NONCE_SIZE = 16
DBC_SIG_SIZE = 32

PARAM_GET_FMAX_CAP = (0x3,)
PARAM_SET_FMAX_CAP = (0x4,)
PARAM_GET_PWR_CAP = (0x5,)
PARAM_SET_PWR_CAP = (0x6,)
PARAM_GET_GFX_MODE = (0x7,)
PARAM_SET_GFX_MODE = (0x8,)
PARAM_GET_CURR_TEMP = (0x9,)
PARAM_GET_FMAX_MAX = (0xA,)
PARAM_GET_FMAX_MIN = (0xB,)
PARAM_GET_SOC_PWR_MAX = (0xC,)
PARAM_GET_SOC_PWR_MIN = (0xD,)
PARAM_GET_SOC_PWR_CUR = (0xE,)

DEVICE_NODE = "/dev/dbc"

lib = ctypes.CDLL("./dbc_library.so", mode=ctypes.RTLD_GLOBAL)


def handle_error(code):
    val = code * -1
    raise OSError(val, os.strerror(val))


def get_nonce(device, signature):
    if not device:
        raise ValueError("Device required")
    buf = ctypes.create_string_buffer(DBC_NONCE_SIZE)
    ret = lib.get_nonce(device.fileno(), ctypes.byref(buf), signature)
    if ret:
        handle_error(ret)
    return buf.value


def set_uid(device, new_uid, signature):
    if not signature:
        raise ValueError("Signature required")
    if not new_uid:
        raise ValueError("UID required")
    ret = lib.set_uid(device.fileno(), new_uid, signature)
    if ret:
        handle_error(ret)
    return True


def process_param(device, message, signature, data=None):
    if not signature:
        raise ValueError("Signature required")
    if type(message) != tuple:
        raise ValueError("Expected message tuple")
    arg = ctypes.c_int(data if data else 0)
    ret = lib.process_param(device.fileno(), message[0], signature, ctypes.pointer(arg))
    if ret:
        handle_error(ret)
    return arg, signature

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API