745c33d51885a888a6fea39060b77273a4e688ad
[platform/upstream/glib.git] / gio / kdbus.h
1 /*
2  * Copyright (C) 2013-2014 Kay Sievers
3  * Copyright (C) 2013-2014 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4  * Copyright (C) 2013-2014 Linux Foundation
5  * Copyright (C) 2013-2014 Lennart Poettering
6  * Copyright (C) 2013-2014 Daniel Mack <daniel@zonque.org>
7  * Copyright (C) 2013-2014 David Herrmann <dh.herrmann@gmail.com>
8  *
9  * kdbus is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU Lesser General Public License as published by the
11  * Free Software Foundation; either version 2.1 of the License, or (at
12  * your option) any later version.
13  *
14  * "Everything should be made as simple as possible, but not simpler."
15  *   -- Albert Einstein
16  */
17
18 #ifndef _KDBUS_UAPI_H_
19 #define _KDBUS_UAPI_H_
20
21 #include <linux/ioctl.h>
22 #include <linux/types.h>
23
24 #define KDBUS_IOCTL_MAGIC               0x95
25 #define KDBUS_SRC_ID_KERNEL             (0)
26 #define KDBUS_DST_ID_NAME               (0)
27 #define KDBUS_MATCH_ID_ANY              (~0ULL)
28 #define KDBUS_DST_ID_BROADCAST          (~0ULL)
29
30 /**
31  * struct kdbus_notify_id_change - name registry change message
32  * @id:                 New or former owner of the name
33  * @flags:              flags field from KDBUS_HELLO_*
34  *
35  * Sent from kernel to userspace when the owner or activator of
36  * a well-known name changes.
37  *
38  * Attached to:
39  *   KDBUS_ITEM_ID_ADD
40  *   KDBUS_ITEM_ID_REMOVE
41  */
42 struct kdbus_notify_id_change {
43         __u64 id;
44         __u64 flags;
45 };
46
47 /**
48  * struct kdbus_notify_name_change - name registry change message
49  * @old_id:             ID and flags of former owner of a name
50  * @new_id:             ID and flags of new owner of a name
51  * @name:               Well-known name
52  *
53  * Sent from kernel to userspace when the owner or activator of
54  * a well-known name changes.
55  *
56  * Attached to:
57  *   KDBUS_ITEM_NAME_ADD
58  *   KDBUS_ITEM_NAME_REMOVE
59  *   KDBUS_ITEM_NAME_CHANGE
60  */
61 struct kdbus_notify_name_change {
62         struct kdbus_notify_id_change old_id;
63         struct kdbus_notify_id_change new_id;
64         char name[0];
65 };
66
67 /**
68  * struct kdbus_creds - process credentials
69  * @uid:                User ID
70  * @gid:                Group ID
71  * @pid:                Process ID
72  * @tid:                Thread ID
73  * @starttime:          Starttime of the process
74  *
75  * The starttime of the process PID. This is useful to detect PID overruns
76  * from the client side. i.e. if you use the PID to look something up in
77  * /proc/$PID/ you can afterwards check the starttime field of it, to ensure
78  * you didn't run into a PID overrun.
79  *
80  * Attached to:
81  *   KDBUS_ITEM_CREDS
82  */
83 struct kdbus_creds {
84         __u64 uid;
85         __u64 gid;
86         __u64 pid;
87         __u64 tid;
88         __u64 starttime;
89 };
90
91 /**
92  * struct kdbus_audit - audit information
93  * @sessionid:          The audit session ID
94  * @loginuid:           The audit login uid
95  *
96  * Attached to:
97  *   KDBUS_ITEM_AUDIT
98  */
99 struct kdbus_audit {
100         __u64 sessionid;
101         __u64 loginuid;
102 };
103
104 /**
105  * struct kdbus_timestamp
106  * @seqnum:             Global per-domain message sequence number
107  * @monotonic_ns:       Monotonic timestamp, in nanoseconds
108  * @realtime_ns:        Realtime timestamp, in nanoseconds
109  *
110  * Attached to:
111  *   KDBUS_ITEM_TIMESTAMP
112  */
113 struct kdbus_timestamp {
114         __u64 seqnum;
115         __u64 monotonic_ns;
116         __u64 realtime_ns;
117 };
118
119 /**
120  * struct kdbus_vec - I/O vector for kdbus payload items
121  * @size:               The size of the vector
122  * @address:            Memory address of data buffer
123  * @offset:             Offset in the in-message payload memory,
124  *                      relative to the message head
125  *
126  * Attached to:
127  *   KDBUS_ITEM_PAYLOAD_VEC, KDBUS_ITEM_PAYLOAD_OFF
128  */
129 struct kdbus_vec {
130         __u64 size;
131         union {
132                 __u64 address;
133                 __u64 offset;
134         };
135 };
136
137 /**
138  * struct kdbus_bloom_parameter - bus-wide bloom parameters
139  * @size:               Size of the bit field in bytes (m / 8)
140  * @n_hash:             Number of hash functions used (k)
141  */
142 struct kdbus_bloom_parameter {
143         __u64 size;
144         __u64 n_hash;
145 };
146
147 /**
148  * struct kdbus_bloom_filter - bloom filter containing n elements
149  * @generation:         Generation of the element set in the filter
150  * @data:               Bit field, multiple of 8 bytes
151  */
152 struct kdbus_bloom_filter {
153         __u64 generation;
154         __u64 data[0];
155 };
156
157 /**
158  * struct kdbus_memfd - a kdbus memfd
159  * @size:               The memfd's size
160  * @fd:                 The file descriptor number
161  * @__pad:              Padding to ensure proper alignment and size
162  *
163  * Attached to:
164  *   KDBUS_ITEM_PAYLOAD_MEMFD
165  */
166 struct kdbus_memfd {
167         __u64 size;
168         int fd;
169         __u32 __pad;
170 };
171
172 /**
173  * struct kdbus_name - a registered well-known name with its flags
174  * @flags:              Flags from KDBUS_NAME_*
175  * @name:               Well-known name
176  *
177  * Attached to:
178  *   KDBUS_ITEM_NAME
179  */
180 struct kdbus_name {
181         __u64 flags;
182         char name[0];
183 };
184
185 /**
186  * struct kdbus_policy_access - policy access item
187  * @type:               One of KDBUS_POLICY_ACCESS_* types
188  * @access:             Access to grant
189  * @id:                 For KDBUS_POLICY_ACCESS_USER, the uid
190  *                      For KDBUS_POLICY_ACCESS_GROUP, the gid
191  */
192 struct kdbus_policy_access {
193         __u64 type;     /* USER, GROUP, WORLD */
194         __u64 access;   /* OWN, TALK, SEE */
195         __u64 id;       /* uid, gid, 0 */
196 };
197
198 /**
199  * enum kdbus_item_type - item types to chain data in a list
200  * @_KDBUS_ITEM_NULL:           Uninitialized/invalid
201  * @_KDBUS_ITEM_USER_BASE:      Start of user items
202  * @KDBUS_ITEM_PAYLOAD_VEC:     Vector to data
203  * @KDBUS_ITEM_PAYLOAD_OFF:     Data at returned offset to message head
204  * @KDBUS_ITEM_PAYLOAD_MEMFD:   Data as sealed memfd
205  * @KDBUS_ITEM_FDS:             Attached file descriptors
206  * @KDBUS_ITEM_BLOOM_PARAMETER: Bus-wide bloom parameters, used with
207  *                              KDBUS_CMD_BUS_MAKE, carries a
208  *                              struct kdbus_bloom_parameter
209  * @KDBUS_ITEM_BLOOM_FILTER:    Bloom filter carried with a message, used to
210  *                              match against a bloom mask of a connection,
211  *                              carries a struct kdbus_bloom_filter
212  * @KDBUS_ITEM_BLOOM_MASK:      Bloom mask used to match against a message's
213  *                              bloom filter
214  * @KDBUS_ITEM_DST_NAME:        Destination's well-known name
215  * @KDBUS_ITEM_MAKE_NAME:       Name of domain, bus, endpoint
216  * @KDBUS_ITEM_MEMFD_NAME:      The human readable name of a memfd (debugging)
217  * @KDBUS_ITEM_ATTACH_FLAGS:    Attach-flags, used for updating which metadata
218  *                              a connection subscribes to
219  * @_KDBUS_ITEM_ATTACH_BASE:    Start of metadata attach items
220  * @KDBUS_ITEM_NAME:            Well-know name with flags
221  * @KDBUS_ITEM_ID:              Connection ID
222  * @KDBUS_ITEM_TIMESTAMP:       Timestamp
223  * @KDBUS_ITEM_CREDS:           Process credential
224  * @KDBUS_ITEM_AUXGROUPS:       Auxiliary process groups
225  * @KDBUS_ITEM_PID_COMM:        Process ID "comm" identifier
226  * @KDBUS_ITEM_TID_COMM:        Thread ID "comm" identifier
227  * @KDBUS_ITEM_EXE:             The path of the executable
228  * @KDBUS_ITEM_CMDLINE:         The process command line
229  * @KDBUS_ITEM_CGROUP:          The croup membership
230  * @KDBUS_ITEM_CAPS:            The process capabilities
231  * @KDBUS_ITEM_SECLABEL:        The security label
232  * @KDBUS_ITEM_AUDIT:           The audit IDs
233  * @KDBUS_ITEM_CONN_NAME:       The connection's human-readable name (debugging)
234  * @_KDBUS_ITEM_POLICY_BASE:    Start of policy items
235  * @KDBUS_ITEM_POLICY_ACCESS:   Policy access block
236  * @_KDBUS_ITEM_KERNEL_BASE:    Start of kernel-generated message items
237  * @KDBUS_ITEM_NAME_ADD:        Notify in struct kdbus_notify_name_change
238  * @KDBUS_ITEM_NAME_REMOVE:     Notify in struct kdbus_notify_name_change
239  * @KDBUS_ITEM_NAME_CHANGE:     Notify in struct kdbus_notify_name_change
240  * @KDBUS_ITEM_ID_ADD:          Notify in struct kdbus_notify_id_change
241  * @KDBUS_ITEM_ID_REMOVE:       Notify in struct kdbus_notify_id_change
242  * @KDBUS_ITEM_REPLY_TIMEOUT:   Timeout has been reached
243  * @KDBUS_ITEM_REPLY_DEAD:      Destination died
244  */
245 enum kdbus_item_type {
246         _KDBUS_ITEM_NULL,
247         _KDBUS_ITEM_USER_BASE,
248         KDBUS_ITEM_PAYLOAD_VEC  = _KDBUS_ITEM_USER_BASE,
249         KDBUS_ITEM_PAYLOAD_OFF,
250         KDBUS_ITEM_PAYLOAD_MEMFD,
251         KDBUS_ITEM_FDS,
252         KDBUS_ITEM_BLOOM_PARAMETER,
253         KDBUS_ITEM_BLOOM_FILTER,
254         KDBUS_ITEM_BLOOM_MASK,
255         KDBUS_ITEM_DST_NAME,
256         KDBUS_ITEM_MAKE_NAME,
257         KDBUS_ITEM_MEMFD_NAME,
258         KDBUS_ITEM_ATTACH_FLAGS,
259
260         _KDBUS_ITEM_ATTACH_BASE = 0x1000,
261         KDBUS_ITEM_NAME         = _KDBUS_ITEM_ATTACH_BASE,
262         KDBUS_ITEM_ID,
263         KDBUS_ITEM_TIMESTAMP,
264         KDBUS_ITEM_CREDS,
265         KDBUS_ITEM_AUXGROUPS,
266         KDBUS_ITEM_PID_COMM,
267         KDBUS_ITEM_TID_COMM,
268         KDBUS_ITEM_EXE,
269         KDBUS_ITEM_CMDLINE,
270         KDBUS_ITEM_CGROUP,
271         KDBUS_ITEM_CAPS,
272         KDBUS_ITEM_SECLABEL,
273         KDBUS_ITEM_AUDIT,
274         KDBUS_ITEM_CONN_NAME,
275
276         _KDBUS_ITEM_POLICY_BASE = 0x2000,
277         KDBUS_ITEM_POLICY_ACCESS = _KDBUS_ITEM_POLICY_BASE,
278
279         _KDBUS_ITEM_KERNEL_BASE = 0x8000,
280         KDBUS_ITEM_NAME_ADD     = _KDBUS_ITEM_KERNEL_BASE,
281         KDBUS_ITEM_NAME_REMOVE,
282         KDBUS_ITEM_NAME_CHANGE,
283         KDBUS_ITEM_ID_ADD,
284         KDBUS_ITEM_ID_REMOVE,
285         KDBUS_ITEM_REPLY_TIMEOUT,
286         KDBUS_ITEM_REPLY_DEAD,
287 };
288
289 /**
290  * struct kdbus_item - chain of data blocks
291  * @size:               Overall data record size
292  * @type:               Kdbus_item type of data
293  * @data:               Generic bytes
294  * @data32:             Generic 32 bit array
295  * @data64:             Generic 64 bit array
296  * @str:                Generic string
297  * @id:                 Connection ID
298  * @vec:                KDBUS_ITEM_PAYLOAD_VEC
299  * @creds:              KDBUS_ITEM_CREDS
300  * @audit:              KDBUS_ITEM_AUDIT
301  * @timestamp:          KDBUS_ITEM_TIMESTAMP
302  * @name:               KDBUS_ITEM_NAME
303  * @bloom_parameter:    KDBUS_ITEM_BLOOM_PARAMETER
304  * @bloom_filter:       KDBUS_ITEM_BLOOM_FILTER
305  * @memfd:              KDBUS_ITEM_PAYLOAD_MEMFD
306  * @name_change:        KDBUS_ITEM_NAME_ADD
307  *                      KDBUS_ITEM_NAME_REMOVE
308  *                      KDBUS_ITEM_NAME_CHANGE
309  * @id_change:          KDBUS_ITEM_ID_ADD
310  *                      KDBUS_ITEM_ID_REMOVE
311  * @policy:             KDBUS_ITEM_POLICY_ACCESS
312  */
313 struct kdbus_item {
314         __u64 size;
315         __u64 type;
316         union {
317                 __u8 data[0];
318                 __u32 data32[0];
319                 __u64 data64[0];
320                 char str[0];
321
322                 __u64 id;
323                 struct kdbus_vec vec;
324                 struct kdbus_creds creds;
325                 struct kdbus_audit audit;
326                 struct kdbus_timestamp timestamp;
327                 struct kdbus_name name;
328                 struct kdbus_bloom_parameter bloom_parameter;
329                 struct kdbus_bloom_filter bloom_filter;
330                 struct kdbus_memfd memfd;
331                 int fds[0];
332                 struct kdbus_notify_name_change name_change;
333                 struct kdbus_notify_id_change id_change;
334                 struct kdbus_policy_access policy_access;
335         };
336 };
337
338 /**
339  * enum kdbus_msg_flags - type of message
340  * @KDBUS_MSG_FLAGS_EXPECT_REPLY:       Expect a reply message, used for
341  *                                      method calls. The userspace-supplied
342  *                                      cookie identifies the message and the
343  *                                      respective reply carries the cookie
344  *                                      in cookie_reply
345  * @KDBUS_MSG_FLAGS_SYNC_REPLY:         Wait for destination connection to
346  *                                      reply to this message. The
347  *                                      KDBUS_CMD_MSG_SEND ioctl() will block
348  *                                      until the reply is received, and
349  *                                      offset_reply in struct kdbus_msg will
350  *                                      yield the offset in the sender's pool
351  *                                      where the reply can be found.
352  *                                      This flag is only valid if
353  *                                      @KDBUS_MSG_FLAGS_EXPECT_REPLY is set as
354  *                                      well.
355  * @KDBUS_MSG_FLAGS_NO_AUTO_START:      Do not start a service, if the addressed
356  *                                      name is not currently active
357  */
358 enum kdbus_msg_flags {
359         KDBUS_MSG_FLAGS_EXPECT_REPLY    = 1ULL << 0,
360         KDBUS_MSG_FLAGS_SYNC_REPLY      = 1ULL << 1,
361         KDBUS_MSG_FLAGS_NO_AUTO_START   = 1ULL << 2,
362 };
363
364 /**
365  * enum kdbus_payload_type - type of payload carried by message
366  * @KDBUS_PAYLOAD_KERNEL:       Kernel-generated simple message
367  * @KDBUS_PAYLOAD_DBUS:         D-Bus marshalling "DBusDBus"
368  */
369 enum kdbus_payload_type {
370         KDBUS_PAYLOAD_KERNEL,
371         KDBUS_PAYLOAD_DBUS      = 0x4442757344427573ULL,
372 };
373
374 /**
375  * struct kdbus_msg - the representation of a kdbus message
376  * @size:               Total size of the message
377  * @flags:              Message flags (KDBUS_MSG_FLAGS_*)
378  * @priority:           Message queue priority value
379  * @dst_id:             64-bit ID of the destination connection
380  * @src_id:             64-bit ID of the source connection
381  * @payload_type:       Payload type (KDBUS_PAYLOAD_*)
382  * @cookie:             Userspace-supplied cookie, for the connection
383  *                      to identify its messages
384  * @timeout_ns:         The time to wait for a message reply from the peer.
385  *                      If there is no reply, a kernel-generated message
386  *                      with an attached KDBUS_ITEM_REPLY_TIMEOUT item
387  *                      is sent to @src_id.
388  * @cookie_reply:       A reply to the requesting message with the same
389  *                      cookie. The requesting connection can match its
390  *                      request and the reply with this value
391  * @offset_reply:       If KDBUS_MSG_FLAGS_EXPECT_REPLY, this field will
392  *                      contain the offset in the sender's pool where the
393  *                      reply is stored.
394  * @items:              A list of kdbus_items containing the message payload
395  */
396 struct kdbus_msg {
397         __u64 size;
398         __u64 flags;
399         __s64 priority;
400         __u64 dst_id;
401         __u64 src_id;
402         __u64 payload_type;
403         __u64 cookie;
404         union {
405                 __u64 timeout_ns;
406                 __u64 cookie_reply;
407                 __u64 offset_reply;
408         };
409         struct kdbus_item items[0];
410 } __attribute__((aligned(8)));
411
412 /**
413  * enum kdbus_recv_flags - flags for de-queuing messages
414  * @KDBUS_RECV_PEEK:            Return the next queued message without
415  *                              actually de-queuing it, and without installing
416  *                              any file descriptors or other resources. It is
417  *                              usually used to determine the activating
418  *                              connection of a bus name.
419  * @KDBUS_RECV_DROP:            Drop and free the next queued message and all
420  *                              its resources without actually receiving it.
421  * @KDBUS_RECV_USE_PRIORITY:    Only de-queue messages with the specified or
422  *                              higher priority (lowest values); if not set,
423  *                              the priority value is ignored.
424  */
425 enum kdbus_recv_flags {
426         KDBUS_RECV_PEEK         = 1ULL <<  0,
427         KDBUS_RECV_DROP         = 1ULL <<  1,
428         KDBUS_RECV_USE_PRIORITY = 1ULL <<  2,
429 };
430
431 /**
432  * struct kdbus_cmd_recv - struct to de-queue a buffered message
433  * @flags:              KDBUS_RECV_* flags
434  * @priority:           Minimum priority of the messages to de-queue. Lowest
435  *                      values have the highest priority.
436  * @offset:             Returned offset in the pool where the message is
437  *                      stored. The user must use KDBUS_CMD_FREE to free
438  *                      the allocated memory.
439  *
440  * This struct is used with the KDBUS_CMD_MSG_RECV ioctl.
441  */
442 struct kdbus_cmd_recv {
443         __u64 flags;
444         __s64 priority;
445         __u64 offset;
446 } __attribute__((aligned(8)));
447
448 /**
449  * enum kdbus_policy_access_type - permissions of a policy record
450  * @_KDBUS_POLICY_ACCESS_NULL:  Uninitialized/invalid
451  * @KDBUS_POLICY_ACCESS_USER:   Grant access to a uid
452  * @KDBUS_POLICY_ACCESS_GROUP:  Grant access to gid
453  * @KDBUS_POLICY_ACCESS_WORLD:  World-accessible
454  */
455 enum kdbus_policy_access_type {
456         _KDBUS_POLICY_ACCESS_NULL,
457         KDBUS_POLICY_ACCESS_USER,
458         KDBUS_POLICY_ACCESS_GROUP,
459         KDBUS_POLICY_ACCESS_WORLD,
460 };
461
462 /**
463  * enum kdbus_policy_access_flags - mode flags
464  * @KDBUS_POLICY_OWN:           Allow to own a well-known name
465  *                              Implies KDBUS_POLICY_TALK and KDBUS_POLICY_SEE
466  * @KDBUS_POLICY_TALK:          Allow communication to a well-known name
467  *                              Implies KDBUS_POLICY_SEE
468  * @KDBUS_POLICY_SEE:           Allow to see a well-known name
469  */
470 enum kdbus_policy_type {
471         KDBUS_POLICY_SEE        = 0,
472         KDBUS_POLICY_TALK,
473         KDBUS_POLICY_OWN,
474 };
475
476 /**
477  * enum kdbus_hello_flags - flags for struct kdbus_cmd_hello
478  * @KDBUS_HELLO_ACCEPT_FD:      The connection allows the reception of
479  *                              any passed file descriptors
480  * @KDBUS_HELLO_ACTIVATOR:      Special-purpose connection which registers
481  *                              a well-know name for a process to be started
482  *                              when traffic arrives
483  * @KDBUS_HELLO_POLICY_HOLDER:  Special-purpose connection which registers
484  *                              policy entries for a name. The provided name
485  *                              is not activated and not registered with the
486  *                              name database, it only allows unprivileged
487  *                              connections to aquire a name, talk or discover
488  *                              a service
489  * @KDBUS_HELLO_MONITOR:        Special-purpose connection to monitor
490  *                              bus traffic
491  */
492 enum kdbus_hello_flags {
493         KDBUS_HELLO_ACCEPT_FD           =  1ULL <<  0,
494         KDBUS_HELLO_ACTIVATOR           =  1ULL <<  1,
495         KDBUS_HELLO_POLICY_HOLDER       =  1ULL <<  2,
496         KDBUS_HELLO_MONITOR             =  1ULL <<  3,
497 };
498
499 /**
500  * enum kdbus_attach_flags - flags for metadata attachments
501  * @KDBUS_ATTACH_TIMESTAMP:     Timestamp
502  * @KDBUS_ATTACH_CREDS:         Credentials
503  * @KDBUS_ATTACH_AUXGROUPS:     Auxiliary groups
504  * @KDBUS_ATTACH_NAMES:         Well-known names
505  * @KDBUS_ATTACH_COMM:          The "comm" process identifier
506  * @KDBUS_ATTACH_EXE:           The path of the executable
507  * @KDBUS_ATTACH_CMDLINE:       The process command line
508  * @KDBUS_ATTACH_CGROUP:        The croup membership
509  * @KDBUS_ATTACH_CAPS:          The process capabilities
510  * @KDBUS_ATTACH_SECLABEL:      The security label
511  * @KDBUS_ATTACH_AUDIT:         The audit IDs
512  * @KDBUS_ATTACH_CONN_NAME:     The human-readable connection name
513  * @_KDBUS_ATTACH_ALL:          All of the above
514  */
515 enum kdbus_attach_flags {
516         KDBUS_ATTACH_TIMESTAMP          =  1ULL <<  0,
517         KDBUS_ATTACH_CREDS              =  1ULL <<  1,
518         KDBUS_ATTACH_AUXGROUPS          =  1ULL <<  2,
519         KDBUS_ATTACH_NAMES              =  1ULL <<  3,
520         KDBUS_ATTACH_COMM               =  1ULL <<  4,
521         KDBUS_ATTACH_EXE                =  1ULL <<  5,
522         KDBUS_ATTACH_CMDLINE            =  1ULL <<  6,
523         KDBUS_ATTACH_CGROUP             =  1ULL <<  7,
524         KDBUS_ATTACH_CAPS               =  1ULL <<  8,
525         KDBUS_ATTACH_SECLABEL           =  1ULL <<  9,
526         KDBUS_ATTACH_AUDIT              =  1ULL << 10,
527         KDBUS_ATTACH_CONN_NAME          =  1ULL << 11,
528         _KDBUS_ATTACH_ALL               =  (1ULL << 12) - 1,
529 };
530
531 /**
532  * struct kdbus_cmd_hello - struct to say hello to kdbus
533  * @size:               The total size of the structure
534  * @conn_flags:         Connection flags (KDBUS_HELLO_*).
535  * @attach_flags:       Mask of metadata to attach to each message sent
536  *                      (KDBUS_ATTACH_*)
537  * @bus_flags:          The flags field copied verbatim from the original
538  *                      KDBUS_CMD_BUS_MAKE ioctl. It's intended to be useful
539  *                      to do negotiation of features of the payload that is
540  *                      transferred (kernel â†’ userspace)
541  * @id:                 The ID of this connection (kernel â†’ userspace)
542  * @pool_size:          Size of the connection's buffer where the received
543  *                      messages are placed
544  * @bloom:              The bloom properties of the bus, specified
545  *                      by the bus creator (kernel â†’ userspace)
546  * @id128:              Unique 128-bit ID of the bus (kernel â†’ userspace)
547  * @items:              A list of items
548  *
549  * This struct is used with the KDBUS_CMD_HELLO ioctl.
550  */
551 struct kdbus_cmd_hello {
552         __u64 size;
553         __u64 conn_flags;
554         __u64 attach_flags;
555         __u64 bus_flags;
556         __u64 id;
557         __u64 pool_size;
558         struct kdbus_bloom_parameter bloom;
559         __u8 id128[16];
560         struct kdbus_item items[0];
561 } __attribute__((aligned(8)));
562
563 /**
564  * enum kdbus_make_flags - Flags for KDBUS_CMD_{BUS,EP,NS}_MAKE
565  * @KDBUS_MAKE_ACCESS_GROUP:    Make the device node group-accessible
566  * @KDBUS_MAKE_ACCESS_WORLD:    Make the device node world-accessible
567  */
568 enum kdbus_make_flags {
569         KDBUS_MAKE_ACCESS_GROUP         = 1ULL <<  0,
570         KDBUS_MAKE_ACCESS_WORLD         = 1ULL <<  1,
571 };
572
573 /**
574  * struct kdbus_cmd_make - struct to make a bus, an endpoint or a domain
575  * @size:               The total size of the struct
576  * @flags:              Properties for the bus/ep/domain to create
577  * @items:              Items describing details
578  *
579  * This structure is used with the KDBUS_CMD_BUS_MAKE, KDBUS_CMD_EP_MAKE and
580  * KDBUS_CMD_DOMAIN_MAKE ioctls.
581  */
582 struct kdbus_cmd_make {
583         __u64 size;
584         __u64 flags;
585         struct kdbus_item items[0];
586 } __attribute__((aligned(8)));
587
588 /**
589  * enum kdbus_name_flags - properties of a well-known name
590  * @KDBUS_NAME_REPLACE_EXISTING:        Try to replace name of other connections
591  * @KDBUS_NAME_ALLOW_REPLACEMENT:       Allow the replacement of the name
592  * @KDBUS_NAME_QUEUE:                   Name should be queued if busy
593  * @KDBUS_NAME_IN_QUEUE:                Name is queued
594  * @KDBUS_NAME_ACTIVATOR:               Name is owned by a activator connection
595  */
596 enum kdbus_name_flags {
597         KDBUS_NAME_REPLACE_EXISTING     = 1ULL <<  0,
598         KDBUS_NAME_ALLOW_REPLACEMENT    = 1ULL <<  1,
599         KDBUS_NAME_QUEUE                = 1ULL <<  2,
600         KDBUS_NAME_IN_QUEUE             = 1ULL <<  3,
601         KDBUS_NAME_ACTIVATOR            = 1ULL <<  4,
602 };
603
604 /**
605  * struct kdbus_cmd_name - struct to describe a well-known name
606  * @size:               The total size of the struct
607  * @flags:              Flags for a name entry (KDBUS_NAME_*)
608  * @owner_id:           The current owner of the name
609  * @conn_flags:         The flags of the owning connection (KDBUS_HELLO_*)
610  * @items:              Item list, containing the well-known name as
611  *                      KDBUS_ITEM_NAME
612  *
613  * This structure is used with the KDBUS_CMD_NAME_ACQUIRE ioctl.
614  */
615 struct kdbus_cmd_name {
616         __u64 size;
617         __u64 flags;
618         __u64 owner_id;
619         __u64 conn_flags;
620         struct kdbus_item items[0];
621 } __attribute__((aligned(8)));
622
623 /**
624  * enum kdbus_name_list_flags - what to include into the returned list
625  * @KDBUS_NAME_LIST_UNIQUE:     All active connections
626  * @KDBUS_NAME_LIST_NAMES:      All known well-known names
627  * @KDBUS_NAME_LIST_ACTIVATORS: All activator connections
628  * @KDBUS_NAME_LIST_QUEUED:     All queued-up names
629  */
630 enum kdbus_name_list_flags {
631         KDBUS_NAME_LIST_UNIQUE          = 1ULL <<  0,
632         KDBUS_NAME_LIST_NAMES           = 1ULL <<  1,
633         KDBUS_NAME_LIST_ACTIVATORS      = 1ULL <<  2,
634         KDBUS_NAME_LIST_QUEUED          = 1ULL <<  3,
635 };
636
637 /**
638  * struct kdbus_cmd_name_list - request a list of name entries
639  * @flags:              Flags for the query (KDBUS_NAME_LIST_*)
640  * @offset:             The returned offset in the caller's pool buffer.
641  *                      The user must use KDBUS_CMD_FREE to free the
642  *                      allocated memory.
643  *
644  * This structure is used with the KDBUS_CMD_NAME_LIST ioctl.
645  */
646 struct kdbus_cmd_name_list {
647         __u64 flags;
648         __u64 offset;
649 } __attribute__((aligned(8)));
650
651 /**
652  * struct kdbus_name_list - information returned by KDBUS_CMD_NAME_LIST
653  * @size:               The total size of the structure
654  * @names:              A list of names
655  *
656  * Note that the user is responsible for freeing the allocated memory with
657  * the KDBUS_CMD_FREE ioctl.
658  */
659 struct kdbus_name_list {
660         __u64 size;
661         struct kdbus_cmd_name names[0];
662 };
663
664 /**
665  * struct kdbus_cmd_conn_info - struct used for KDBUS_CMD_CONN_INFO ioctl
666  * @size:               The total size of the struct
667  * @flags:              KDBUS_ATTACH_* flags
668  * @id:                 The 64-bit ID of the connection. If set to zero, passing
669  *                      @name is required. kdbus will look up the name to
670  *                      determine the ID in this case.
671  * @offset:             Returned offset in the caller's pool buffer where the
672  *                      kdbus_conn_info struct result is stored. The user must
673  *                      use KDBUS_CMD_FREE to free the allocated memory.
674  * @name:               The optional well-known name to look up. Only needed in
675  *                      case @id is zero.
676  *
677  * On success, the KDBUS_CMD_CONN_INFO ioctl will return 0 and @offset will
678  * tell the user the offset in the connection pool buffer at which to find the
679  * result in a struct kdbus_conn_info.
680  */
681 struct kdbus_cmd_conn_info {
682         __u64 size;
683         __u64 flags;
684         __u64 id;
685         __u64 offset;
686         char name[0];
687 } __attribute__((aligned(8)));
688
689 /**
690  * struct kdbus_conn_info - information returned by KDBUS_CMD_CONN_INFO
691  * @size:               The total size of the struct
692  * @id:                 The connection's 64-bit ID
693  * @flags:              The connection's flags
694  * @items:              A list of struct kdbus_item
695  *
696  * Note that the user is responsible for freeing the allocated memory with
697  * the KDBUS_CMD_FREE ioctl.
698  */
699 struct kdbus_conn_info {
700         __u64 size;
701         __u64 id;
702         __u64 flags;
703         struct kdbus_item items[0];
704 };
705
706 /**
707  * struct kdbus_cmd_update - update flags of a connection
708  * @size:               The total size of the struct
709  * @items:              A list of struct kdbus_item
710  *
711  * This struct is used with the KDBUS_CMD_CONN_UPDATE ioctl.
712  */
713 struct kdbus_cmd_update {
714         __u64 size;
715         struct kdbus_item items[0];
716 } __attribute__((aligned(8)));
717
718 /**
719  * struct kdbus_cmd_match - struct to add or remove matches
720  * @size:               The total size of the struct
721  * @cookie:             Userspace supplied cookie. When removing, the cookie
722  *                      identifies the match to remove
723  * @items:              A list of items for additional information
724  *
725  * This structure is used with the KDBUS_CMD_ADD_MATCH and
726  * KDBUS_CMD_REMOVE_MATCH ioctl.
727  */
728 struct kdbus_cmd_match {
729         __u64 size;
730         __u64 cookie;
731         struct kdbus_item items[0];
732 } __attribute__((aligned(8)));
733
734 /**
735  * enum kdbus_ioctl_type - Ioctl API
736  * @KDBUS_CMD_BUS_MAKE:         After opening the "control" device node, this
737  *                              command creates a new bus with the specified
738  *                              name. The bus is immediately shut down and
739  *                              cleaned up when the opened "control" device node
740  *                              is closed.
741  * @KDBUS_CMD_DOMAIN_MAKE:      Similar to KDBUS_CMD_BUS_MAKE, but it creates a
742  *                              new kdbus domain.
743  * @KDBUS_CMD_EP_MAKE:          Creates a new named special endpoint to talk to
744  *                              the bus. Such endpoints usually carry a more
745  *                              restrictive policy and grant restricted access
746  *                              to specific applications.
747  * @KDBUS_CMD_HELLO:            By opening the bus device node a connection is
748  *                              created. After a HELLO the opened connection
749  *                              becomes an active peer on the bus.
750  * @KDBUS_CMD_BYEBYE:           Disconnect a connection. If there are no
751  *                              messages queued up in the connection's pool,
752  *                              the call succeeds, and the handle is rendered
753  *                              unusable. Otherwise, -EBUSY is returned without
754  *                              any further side-effects.
755  * @KDBUS_CMD_MSG_SEND:         Send a message and pass data from userspace to
756  *                              the kernel.
757  * @KDBUS_CMD_MSG_RECV:         Receive a message from the kernel which is
758  *                              placed in the receiver's pool.
759  * @KDBUS_CMD_MSG_CANCEL:       Cancel a pending request of a message that
760  *                              blocks while waiting for a reply. The parameter
761  *                              denotes the cookie of the message in flight.
762  * @KDBUS_CMD_FREE:             Release the allocated memory in the receiver's
763  *                              pool.
764  * @KDBUS_CMD_NAME_ACQUIRE:     Request a well-known bus name to associate with
765  *                              the connection. Well-known names are used to
766  *                              address a peer on the bus.
767  * @KDBUS_CMD_NAME_RELEASE:     Release a well-known name the connection
768  *                              currently owns.
769  * @KDBUS_CMD_NAME_LIST:        Retrieve the list of all currently registered
770  *                              well-known and unique names.
771  * @KDBUS_CMD_CONN_INFO:        Retrieve credentials and properties of the
772  *                              initial creator of the connection. The data was
773  *                              stored at registration time and does not
774  *                              necessarily represent the connected process or
775  *                              the actual state of the process.
776  * @KDBUS_CMD_CONN_UPDATE:      Update the properties of a connection. Used to
777  *                              update the metadata subscription mask and
778  *                              policy.
779  * @KDBUS_CMD_EP_UPDATE:        Update the properties of a custom enpoint. Used
780  *                              to update the policy.
781  * @KDBUS_CMD_MATCH_ADD:        Install a match which broadcast messages should
782  *                              be delivered to the connection.
783  * @KDBUS_CMD_MATCH_REMOVE:     Remove a current match for broadcast messages.
784  */
785 enum kdbus_ioctl_type {
786         KDBUS_CMD_BUS_MAKE =            _IOW(KDBUS_IOCTL_MAGIC, 0x00,
787                                              struct kdbus_cmd_make),
788         KDBUS_CMD_DOMAIN_MAKE =         _IOW(KDBUS_IOCTL_MAGIC, 0x10,
789                                              struct kdbus_cmd_make),
790         KDBUS_CMD_EP_MAKE =             _IOW(KDBUS_IOCTL_MAGIC, 0x20,
791                                              struct kdbus_cmd_make),
792
793         KDBUS_CMD_HELLO =               _IOWR(KDBUS_IOCTL_MAGIC, 0x30,
794                                               struct kdbus_cmd_hello),
795         KDBUS_CMD_BYEBYE =              _IO(KDBUS_IOCTL_MAGIC, 0x31),
796
797         KDBUS_CMD_MSG_SEND =            _IOWR(KDBUS_IOCTL_MAGIC, 0x40,
798                                               struct kdbus_msg),
799         KDBUS_CMD_MSG_RECV =            _IOWR(KDBUS_IOCTL_MAGIC, 0x41,
800                                               struct kdbus_cmd_recv),
801         KDBUS_CMD_MSG_CANCEL =          _IOW(KDBUS_IOCTL_MAGIC, 0x42, __u64 *),
802         KDBUS_CMD_FREE =                _IOW(KDBUS_IOCTL_MAGIC, 0x43, __u64 *),
803
804         KDBUS_CMD_NAME_ACQUIRE =        _IOWR(KDBUS_IOCTL_MAGIC, 0x50,
805                                               struct kdbus_cmd_name),
806         KDBUS_CMD_NAME_RELEASE =        _IOW(KDBUS_IOCTL_MAGIC, 0x51,
807                                              struct kdbus_cmd_name),
808         KDBUS_CMD_NAME_LIST =           _IOWR(KDBUS_IOCTL_MAGIC, 0x52,
809                                               struct kdbus_cmd_name_list),
810
811         KDBUS_CMD_CONN_INFO =           _IOWR(KDBUS_IOCTL_MAGIC, 0x60,
812                                               struct kdbus_cmd_conn_info),
813         KDBUS_CMD_CONN_UPDATE =         _IOW(KDBUS_IOCTL_MAGIC, 0x61,
814                                              struct kdbus_cmd_update),
815
816         KDBUS_CMD_EP_UPDATE =           _IOW(KDBUS_IOCTL_MAGIC, 0x71,
817                                              struct kdbus_cmd_update),
818
819         KDBUS_CMD_MATCH_ADD =           _IOW(KDBUS_IOCTL_MAGIC, 0x80,
820                                              struct kdbus_cmd_match),
821         KDBUS_CMD_MATCH_REMOVE =        _IOW(KDBUS_IOCTL_MAGIC, 0x81,
822                                              struct kdbus_cmd_match),
823 };
824
825 #endif /* _KDBUS_UAPI_H_ */