1 /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 #pragma once 3 4 #include <endian.h> 5 6 #include "macro.h" 7 8 /* Packet header */ 9 10 struct _packed_ bus_header { 11 /* The first four fields are identical for dbus1, and dbus2 */ 12 uint8_t endian; 13 uint8_t type; 14 uint8_t flags; 15 uint8_t version; 16 17 union _packed_ { 18 /* dbus1: Used for SOCK_STREAM connections */ 19 struct _packed_ { 20 uint32_t body_size; 21 22 /* Note that what the bus spec calls "serial" we'll call 23 "cookie" instead, because we don't want to imply that the 24 cookie was in any way monotonically increasing. */ 25 uint32_t serial; 26 uint32_t fields_size; 27 } dbus1; 28 29 /* dbus2: Used for kdbus connections */ 30 struct _packed_ { 31 uint32_t _reserved; 32 uint64_t cookie; 33 } dbus2; 34 35 /* Note that both header versions have the same size! */ 36 }; 37 }; 38 39 /* Endianness */ 40 41 enum { 42 _BUS_INVALID_ENDIAN = 0, 43 BUS_LITTLE_ENDIAN = 'l', 44 BUS_BIG_ENDIAN = 'B', 45 #if __BYTE_ORDER == __BIG_ENDIAN 46 BUS_NATIVE_ENDIAN = BUS_BIG_ENDIAN, 47 BUS_REVERSE_ENDIAN = BUS_LITTLE_ENDIAN 48 #else 49 BUS_NATIVE_ENDIAN = BUS_LITTLE_ENDIAN, 50 BUS_REVERSE_ENDIAN = BUS_BIG_ENDIAN 51 #endif 52 }; 53 54 /* Flags */ 55 56 enum { 57 BUS_MESSAGE_NO_REPLY_EXPECTED = 1 << 0, 58 BUS_MESSAGE_NO_AUTO_START = 1 << 1, 59 BUS_MESSAGE_ALLOW_INTERACTIVE_AUTHORIZATION = 1 << 2, 60 }; 61 62 /* Header fields */ 63 64 enum { 65 _BUS_MESSAGE_HEADER_INVALID = 0, 66 BUS_MESSAGE_HEADER_PATH, 67 BUS_MESSAGE_HEADER_INTERFACE, 68 BUS_MESSAGE_HEADER_MEMBER, 69 BUS_MESSAGE_HEADER_ERROR_NAME, 70 BUS_MESSAGE_HEADER_REPLY_SERIAL, 71 BUS_MESSAGE_HEADER_DESTINATION, 72 BUS_MESSAGE_HEADER_SENDER, 73 BUS_MESSAGE_HEADER_SIGNATURE, 74 BUS_MESSAGE_HEADER_UNIX_FDS, 75 _BUS_MESSAGE_HEADER_MAX 76 }; 77 78 /* RequestName parameters */ 79 80 enum { 81 BUS_NAME_ALLOW_REPLACEMENT = 1 << 0, 82 BUS_NAME_REPLACE_EXISTING = 1 << 1, 83 BUS_NAME_DO_NOT_QUEUE = 1 << 2, 84 }; 85 86 /* RequestName returns */ 87 enum { 88 BUS_NAME_PRIMARY_OWNER = 1, 89 BUS_NAME_IN_QUEUE = 2, 90 BUS_NAME_EXISTS = 3, 91 BUS_NAME_ALREADY_OWNER = 4 92 }; 93 94 /* ReleaseName returns */ 95 enum { 96 BUS_NAME_RELEASED = 1, 97 BUS_NAME_NON_EXISTENT = 2, 98 BUS_NAME_NOT_OWNER = 3, 99 }; 100 101 /* StartServiceByName returns */ 102 enum { 103 BUS_START_REPLY_SUCCESS = 1, 104 BUS_START_REPLY_ALREADY_RUNNING = 2, 105 }; 106