Merge changes I795ea4d7,I4871ee62
[platform/upstream/dbus.git] / dbus / kdbus.h
1 /*
2  * Copyright (C) 2013 Kay Sievers
3  * Copyright (C) 2013 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4  * Copyright (C) 2013 Linux Foundation
5  * Copyright (C) 2013 Lennart Poettering
6  * Copyright (C) 2013 Daniel Mack <daniel@zonque.org>
7  *
8  * kdbus is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Lesser General Public License as published by the
10  * Free Software Foundation; either version 2.1 of the License, or (at
11  * your option) any later version.
12  */
13
14 #ifndef _KDBUS_H_
15 #define _KDBUS_H_
16
17 #ifndef __KERNEL__
18 #include <sys/ioctl.h>
19 #include <sys/types.h>
20 #include <linux/types.h>
21 #endif
22
23 #define KDBUS_IOC_MAGIC                 0x95
24 #define KDBUS_SRC_ID_KERNEL             (0)
25 #define KDBUS_DST_ID_NAME               (0)
26 #define KDBUS_MATCH_SRC_ID_ANY          (~0ULL)
27 #define KDBUS_DST_ID_BROADCAST          (~0ULL)
28
29 /**
30  * struct kdbus_notify_name_change - name registry change message
31  * @old_id:             Former owner of a name
32  * @new_id:             New owner of a name
33  * @old_flags:          flags from KDBUS_NAME_* the name entry used to have
34  * @new_flags:          flags from KDBUS_NAME_* the name entry has now
35  * @name:               Well-known name
36  *
37  * Sent from kernel to userspace when the owner or activator of
38  * a well-known name changes.
39  *
40  * Attached to:
41  *   KDBUS_ITEM_NAME_ADD
42  *   KDBUS_ITEM_NAME_REMOVE
43  *   KDBUS_ITEM_NAME_CHANGE
44  */
45 struct kdbus_notify_name_change {
46         __u64 old_id;
47         __u64 new_id;
48         __u64 old_flags;
49         __u64 new_flags;
50         char name[0];
51 };
52
53 /**
54  * struct kdbus_notify_id_change - name registry change message
55  * @id:                 New or former owner of the name
56  * @flags:              flags field from KDBUS_HELLO_*
57  *
58  * Sent from kernel to userspace when the owner or activator of
59  * a well-known name changes.
60  *
61  * Attached to:
62  *   KDBUS_ITEM_ID_ADD
63  *   KDBUS_ITEM_ID_REMOVE
64  */
65 struct kdbus_notify_id_change {
66         __u64 id;
67         __u64 flags;
68 };
69
70 /**
71  * struct kdbus_creds - process credentials
72  * @uid:                User ID
73  * @gid:                Group ID
74  * @pid:                Process ID
75  * @tid:                Thread ID
76  * @starttime:          Starttime of the process
77  *
78  * The starttime of the process PID. This is useful to detect PID overruns
79  * from the client side. i.e. if you use the PID to look something up in
80  * /proc/$PID/ you can afterwards check the starttime field of it, to ensure
81  * you didn't run into a PID overrun.
82  *
83  * Attached to:
84  *   KDBUS_ITEM_CREDS
85  */
86 struct kdbus_creds {
87         __u64 uid;
88         __u64 gid;
89         __u64 pid;
90         __u64 tid;
91         __u64 starttime;
92 };
93
94 /**
95  * struct kdbus_audit - audit information
96  * @sessionid:          The audit session ID
97  * @loginuid:           The audit login uid
98  *
99  * Attached to:
100  *   KDBUS_ITEM_AUDIT
101  */
102 struct kdbus_audit {
103         __u64 sessionid;
104         __u64 loginuid;
105 };
106
107 /**
108  * struct kdbus_timestamp
109  * @monotonic_ns:       Monotonic timestamp, in nanoseconds
110  * @realtime_ns:        Realtime timestamp, in nanoseconds
111  *
112  * Attached to:
113  *   KDBUS_ITEM_TIMESTAMP
114  */
115 struct kdbus_timestamp {
116         __u64 monotonic_ns;
117         __u64 realtime_ns;
118 };
119
120 /**
121  * struct kdbus_vec - I/O vector for kdbus payload items
122  * @size:               The size of the vector
123  * @address:            Memory address for memory addresses
124  * @offset:             Offset in the in-message payload memory
125  *
126  * Attached to:
127  *   KDBUS_ITEM_PAYLOAD_VEC
128  */
129 struct kdbus_vec {
130         __u64 size;
131         union {
132                 __u64 address;
133                 __u64 offset;
134         };
135 };
136
137 /**
138  * struct kdbus_memfd - a kdbus memfd
139  * @size:               The memfd's size
140  * @fd:                 The file descriptor number
141  * @__pad:              Padding to make the struct aligned
142  *
143  * Attached to:
144  *   KDBUS_ITEM_PAYLOAD_MEMFD
145  */
146 struct kdbus_memfd {
147         __u64 size;
148         int fd;
149         __u32 __pad;
150 };
151
152 /**
153  * struct kdbus_name - a registered well-known name with its flags
154  * @flags:              flags from KDBUS_NAME_*
155  * @name:               well-known name
156  *
157  * Attached to:
158  *   KDBUS_ITEM_NAME
159  */
160 struct kdbus_name {
161         __u64 flags;
162         char name[0];
163 };
164
165 /**
166  * struct kdbus_policy_access - policy access item
167  * @type:               One of KDBUS_POLICY_ACCESS_* types
168  * @bits:               Access to grant. One of KDBUS_POLICY_*
169  * @id:                 For KDBUS_POLICY_ACCESS_USER, the uid
170  *                      For KDBUS_POLICY_ACCESS_GROUP, the gid
171  *
172  * Embedded in:
173  *   struct kdbus_policy
174  */
175 struct kdbus_policy_access {
176         __u64 type;     /* USER, GROUP, WORLD */
177         __u64 bits;     /* RECV, SEND, OWN */
178         __u64 id;       /* uid, gid, 0 */
179 };
180
181 /**
182  * struct kdbus_policy - a policy item
183  * @access:             Policy access details
184  * @name:               Well-known name to grant access to
185  *
186  * Attached to:
187  *   KDBUS_POLICY_ACCESS
188  *   KDBUS_ITEM_POLICY_NAME
189  */
190 struct kdbus_policy {
191         union {
192                 struct kdbus_policy_access access;
193                 char name[0];
194         };
195 };
196
197 /**
198  * enum kdbus_item_type - item types to chain data in a list
199  * @KDBUS_ITEM_PAYLOAD_VEC:     Vector to data
200  * @KDBUS_ITEM_PAYLOAD_OFF:     Data at returned offset in the pool
201  * @KDBUS_ITEM_PAYLOAD_MEMFD:   Data as sealed memfd
202  * @KDBUS_ITEM_FDS:             Attached file descriptors
203  * @KDBUS_ITEM_BLOOM:           For broadcasts, carries bloom filter
204  * @KDBUS_ITEM_DST_NAME:        Destination's well-known name
205  * @KDBUS_ITEM_PRIORITY:        Queue priority for message
206  * @KDBUS_ITEM_MAKE_NAME:       Name of namespace, bus, endpoint
207  * @KDBUS_ITEM_POLICY_NAME:     Policy in struct kdbus_policy
208  * @KDBUS_ITEM_POLICY_ACCESS:   Policy in struct kdbus_policy
209  * @KDBUS_ITEM_NAME:            Well-know name with flags
210  * @KDBUS_ITEM_ACTIVATOR_NAME:  Well-known name for the activator
211  * @KDBUS_ITEM_TIMESTAMP:       Timestamp
212  * @KDBUS_ITEM_CREDS:           Process credential
213  * @KDBUS_ITEM_PID_COMM:        Process ID "comm" identifier
214  * @KDBUS_ITEM_TID_COMM:        Thread ID "comm" identifier
215  * @KDBUS_ITEM_EXE:             The path of the executable
216  * @KDBUS_ITEM_CMDLINE:         The process command line
217  * @KDBUS_ITEM_CGROUP:          The croup membership
218  * @KDBUS_ITEM_CAPS:            The process capabilities
219  * @KDBUS_ITEM_SECLABEL:        The security label
220  * @KDBUS_ITEM_AUDIT:           The audit IDs
221  * @KDBUS_ITEM_NAME_ADD:        Notify in struct kdbus_notify_name_change
222  * @KDBUS_ITEM_NAME_REMOVE:     Notify in struct kdbus_notify_name_change
223  * @KDBUS_ITEM_NAME_CHANGE:     Notify in struct kdbus_notify_name_change
224  * @KDBUS_ITEM_ID_ADD:          Notify in struct kdbus_notify_id_change
225  * @KDBUS_ITEM_ID_REMOVE:       Notify in struct kdbus_notify_id_change
226  * @KDBUS_ITEM_REPLY_TIMEOUT:   Timeout has been reached
227  * @KDBUS_ITEM_REPLY_DEAD:      Destination died
228  */
229 enum kdbus_item_type {
230         _KDBUS_ITEM_NULL,
231         _KDBUS_ITEM_USER_BASE,
232         KDBUS_ITEM_PAYLOAD_VEC  = _KDBUS_ITEM_USER_BASE,
233         KDBUS_ITEM_PAYLOAD_OFF,
234         KDBUS_ITEM_PAYLOAD_MEMFD,
235         KDBUS_ITEM_FDS,
236         KDBUS_ITEM_BLOOM,
237         KDBUS_ITEM_DST_NAME,
238         KDBUS_ITEM_PRIORITY,
239         KDBUS_ITEM_MAKE_NAME,
240
241         _KDBUS_ITEM_POLICY_BASE = 0x400,
242         KDBUS_ITEM_POLICY_NAME = _KDBUS_ITEM_POLICY_BASE,
243         KDBUS_ITEM_POLICY_ACCESS,
244
245         _KDBUS_ITEM_ATTACH_BASE = 0x600,
246         KDBUS_ITEM_NAME         = _KDBUS_ITEM_ATTACH_BASE,
247         KDBUS_ITEM_ACTIVATOR_NAME,
248         KDBUS_ITEM_TIMESTAMP,
249         KDBUS_ITEM_CREDS,
250         KDBUS_ITEM_PID_COMM,
251         KDBUS_ITEM_TID_COMM,
252         KDBUS_ITEM_EXE,
253         KDBUS_ITEM_CMDLINE,
254         KDBUS_ITEM_CGROUP,
255         KDBUS_ITEM_CAPS,
256         KDBUS_ITEM_SECLABEL,
257         KDBUS_ITEM_AUDIT,
258
259 #ifdef KDBUS_FOR_SBB
260         KDBUS_ITEM_SBB_DST_NAME,                /* destination name for sbb agent purpose */
261         KDBUS_ITEM_SBB_BLOOM,
262 #endif
263
264         _KDBUS_ITEM_KERNEL_BASE = 0x800,
265         KDBUS_ITEM_NAME_ADD     = _KDBUS_ITEM_KERNEL_BASE,
266         KDBUS_ITEM_NAME_REMOVE,
267         KDBUS_ITEM_NAME_CHANGE,
268         KDBUS_ITEM_ID_ADD,
269         KDBUS_ITEM_ID_REMOVE,
270         KDBUS_ITEM_REPLY_TIMEOUT,
271         KDBUS_ITEM_REPLY_DEAD,
272 };
273
274 /**
275  * struct kdbus_item - chain of data blocks
276  * @size:               Overall data record size
277  * @type:               Kdbus_item type of data
278  * @data:               Generic bytes
279  * @data32:             Generic 32 bit array
280  * @data64:             Generic 64 bit array
281  * @str:                Generic string
282  * @id:                 Connection ID
283  * @vec:                KDBUS_ITEM_PAYLOAD_VEC
284  * @creds:              KDBUS_ITEM_CREDS
285  * @audit:              KDBUS_ITEM_AUDIT
286  * @timestamp:          KDBUS_ITEM_TIMESTAMP
287  * @name:               KDBUS_ITEM_NAME
288  * @memfd:              KDBUS_ITEM_PAYLOAD_MEMFD
289  * @name_change:        KDBUS_ITEM_NAME_ADD
290  *                      KDBUS_ITEM_NAME_REMOVE
291  *                      KDBUS_ITEM_NAME_CHANGE
292  * @id_change:          KDBUS_ITEM_ID_ADD
293  *                      KDBUS_ITEM_ID_REMOVE
294  * @policy:             KDBUS_ITEM_POLICY_NAME
295  *                      KDBUS_ITEM_POLICY_ACCESS
296  */
297 struct kdbus_item {
298         __u64 size;
299         __u64 type;
300         union {
301                 __u8 data[0];
302                 __u32 data32[0];
303                 __u64 data64[0];
304                 char str[0];
305
306                 __u64 id;
307                 struct kdbus_vec vec;
308                 struct kdbus_creds creds;
309                 struct kdbus_audit audit;
310                 struct kdbus_timestamp timestamp;
311                 struct kdbus_name name;
312                 struct kdbus_memfd memfd;
313                 int fds[0];
314                 struct kdbus_notify_name_change name_change;
315                 struct kdbus_notify_id_change id_change;
316                 struct kdbus_policy policy;
317         };
318 };
319
320 /**
321  * enum kdbus_msg_flags - type of message
322  * @KDBUS_MSG_FLAGS_EXPECT_REPLY:       Expect a reply message, used for method
323  *                                      calls. The cookie identifies the
324  *                                      message and the respective reply
325  * @KDBUS_MSG_FLAGS_NO_AUTO_START:      Do not start a service, if the addressed
326  *                                      name is not currently active
327  */
328 enum kdbus_msg_flags {
329         KDBUS_MSG_FLAGS_EXPECT_REPLY    = 1 << 0,
330         KDBUS_MSG_FLAGS_NO_AUTO_START   = 1 << 1,
331 };
332
333 /**
334  * enum kdbus_payload_type - type of payload carried by message
335  * @KDBUS_PAYLOAD_KERNEL:       Kernel-generated simple message
336  * @KDBUS_PAYLOAD_DBUS:         D-Bus marshalling
337  */
338 enum kdbus_payload_type {
339         KDBUS_PAYLOAD_KERNEL,
340         KDBUS_PAYLOAD_DBUS      = 0x4442757344427573ULL, /* 'DBusDBus' */
341 };
342
343 /**
344  * struct kdbus_msg - the representation of a kdbus message
345  * @size:               Total size of the message
346  * @flags:              Message flags (KDBUS_MSG_FLAGS_*)
347  * @dst_id:             64-bit ID of the destination connection
348  * @src_id:             64-bit ID of the source connection
349  * @payload_type:       Payload type (KDBUS_PAYLOAD_*)
350  * @cookie:             Userspace-supplied cookie
351  * @cookie_reply:       For kernel-generated messages, this is the cookie
352  *                      the message is a reply to
353  * @timeout_ns:         For non-kernel-generated messages, this denotes the
354  *                      message timeout in nanoseconds. A message has to be
355  *                      received with KDBUS_CMD_MSG_RECV by the destination
356  *                      connection within this time frame. For messages that
357  *                      have KDBUS_MSG_FLAGS_EXPECT_REPLY set in @flags,
358  *                      this value also denotes the timeout for the reply to
359  *                      this message. If there is no reply, or the message is
360  *                      not received in time by the other side, a
361  *                      kernel-generated message with an attached
362  *                      KDBUS_ITEM_REPLY_TIMEOUT item is sent to @src_id.
363  *                      A 0-value is only valid if KDBUS_MSG_FLAGS_EXPECT_REPLY
364  *                      is unset in @flags.
365  * @items:              A list of kdbus_items containing the message payload
366  */
367 struct kdbus_msg {
368         __u64 size;
369         __u64 flags;
370         __u64 dst_id;
371         __u64 src_id;
372         __u64 payload_type;
373         __u64 cookie;
374         union {
375                 __u64 cookie_reply;
376                 __u64 timeout_ns;
377         };
378         struct kdbus_item items[0];
379 };
380
381 /**
382  * enum kdbus_policy_access_type - permissions of a policy record
383  * @KDBUS_POLICY_ACCESS_USER:   Grant access to a uid
384  * @KDBUS_POLICY_ACCESS_GROUP:  Grant access to gid
385  * @KDBUS_POLICY_ACCESS_WORLD:  World-accessible
386  */
387 enum kdbus_policy_access_type {
388         _KDBUS_POLICY_ACCESS_NULL,
389         KDBUS_POLICY_ACCESS_USER,
390         KDBUS_POLICY_ACCESS_GROUP,
391         KDBUS_POLICY_ACCESS_WORLD,
392 };
393
394 /**
395  * enum kdbus_policy_access_flags - mode flags
396  * @KDBUS_POLICY_RECV:          Allow receive
397  * @KDBUS_POLICY_SEND:          Allow send
398  * @KDBUS_POLICY_OWN:           Allow to own a well-known name
399  */
400 enum kdbus_policy_type {
401         KDBUS_POLICY_RECV               = 1 <<  2,
402         KDBUS_POLICY_SEND               = 1 <<  1,
403         KDBUS_POLICY_OWN                = 1 <<  0,
404 };
405
406 /**
407  * struct kdbus_cmd_policy - a series of policies to upload
408  * @size:               The total size of the structure
409  * @policies:           The policies to upload
410  *
411  * A KDBUS_POLICY_NAME must always preceeds a KDBUS_POLICY_ACCESS entry.
412  * A new KDBUS_POLICY_NAME can be added after KDBUS_POLICY_ACCESS for
413  * chaining multiple policies together.
414  */
415 struct kdbus_cmd_policy {
416         __u64 size;
417         struct kdbus_item policies[0];
418 };
419
420 /**
421  * enum kdbus_hello_flags - flags for struct kdbus_cmd_hello
422  * @KDBUS_HELLO_ACTIVATOR:              The connection registers a name for activation
423  *                              by well-know name
424  * @KDBUS_HELLO_ACCEPT_FD:      The connection allows the receiving of
425  *                              any passed file descriptors
426  */
427 enum kdbus_hello_flags {
428         KDBUS_HELLO_ACTIVATOR           =  1 <<  0,
429         KDBUS_HELLO_ACCEPT_FD           =  1 <<  1,
430
431 #ifdef KDBUS_FOR_SBB
432         /*Flags for SBB*/
433         KDBUS_HELLO_IAMAGENT            =  1 << 30,
434 #endif
435
436 };
437
438 /**
439  * enum kdbus_attach_flags - flags for metadata attachments
440  * @KDBUS_ATTACH_TIMESTAMP:     Timestamp
441  * @KDBUS_ATTACH_CREDS:         Credentials
442  * @KDBUS_ATTACH_NAMES:         Well-known names
443  * @KDBUS_ATTACH_COMM:          The "comm" process identifier
444  * @KDBUS_ATTACH_EXE:           The path of the executable
445  * @KDBUS_ATTACH_CMDLINE:       The process command line
446  * @KDBUS_ATTACH_CGROUP:        The croup membership
447  * @KDBUS_ATTACH_CAPS:          The process capabilities
448  * @KDBUS_ATTACH_SECLABEL:      The security label
449  * @KDBUS_ATTACH_AUDIT:         The audit IDs
450  */
451 enum kdbus_attach_flags {
452         KDBUS_ATTACH_TIMESTAMP          =  1 <<  0,
453         KDBUS_ATTACH_CREDS              =  1 <<  1,
454         KDBUS_ATTACH_NAMES              =  1 <<  2,
455         KDBUS_ATTACH_COMM               =  1 <<  3,
456         KDBUS_ATTACH_EXE                =  1 <<  4,
457         KDBUS_ATTACH_CMDLINE            =  1 <<  5,
458         KDBUS_ATTACH_CGROUP             =  1 <<  6,
459         KDBUS_ATTACH_CAPS               =  1 <<  7,
460         KDBUS_ATTACH_SECLABEL           =  1 <<  8,
461         KDBUS_ATTACH_AUDIT              =  1 <<  9,
462 };
463
464 /**
465  * struct kdbus_cmd_hello - struct to say hello to kdbus
466  * @size:               The total size of the structure
467  * @conn_flags:         Connection flags (KDBUS_HELLO_*). The kernel will
468  *                      return its capabilities in that field.
469  * @attach_flags:       Mask of metadata to attach to each message sent
470  *                      (KDBUS_ATTACH_*)
471  * @bus_flags:          The flags field copied verbatim from the original
472  *                      KDBUS_CMD_BUS_MAKE ioctl. It's intended to be useful
473  *                      to do negotiation of features of the payload that is
474  *                      transferred (kernel â†’ userspace)
475  * @id:                 The ID of this connection (kernel â†’ userspace)
476  * @bloom_size:         The bloom filter size chosen by the owner
477  *                      (kernel â†’ userspace)
478  * @pool_size:          Maximum size of the pool buffer (kernel â†’ userspace)
479  * @id128:              Unique 128-bit ID of the bus (kernel â†’ userspace)
480  * @items:              A list of items
481  *
482  * This struct is used with the KDBUS_CMD_HELLO ioctl. See the ioctl
483  * documentation for more information.
484  */
485 struct kdbus_cmd_hello {
486         __u64 size;
487         __u64 conn_flags;
488         __u64 attach_flags;
489         __u64 bus_flags;
490         __u64 id;
491         __u64 bloom_size;
492         __u64 pool_size;
493         __u8 id128[16];
494         struct kdbus_item items[0];
495 };
496
497 /* Flags for KDBUS_CMD_{BUS,EP,NS}_MAKE */
498 enum kdbus_make_flags {
499         KDBUS_MAKE_ACCESS_GROUP         = 1 <<  0,
500         KDBUS_MAKE_ACCESS_WORLD         = 1 <<  1,
501         KDBUS_MAKE_POLICY_OPEN          = 1 <<  2,
502
503 #ifdef KDBUS_FOR_SBB
504         KDBUS_MAKE_SBB_OFFSET           = (__u64)1 << 31,
505 #endif
506 };
507
508 /**
509  * struct kdbus_cmd_bus_make - struct to make a bus
510  * @size:               The total size of the struct
511  * @flags:              Properties for the bus to create
512  * @bloom_size:         Size of the bloom filter for this bus
513  * @items:              Items describing details such as the name of the bus
514  *
515  * This structure is used with the KDBUS_CMD_BUS_MAKE ioctl.
516  */
517 struct kdbus_cmd_bus_make {
518         __u64 size;
519         __u64 flags;
520         __u64 bloom_size;
521         struct kdbus_item items[0];
522 };
523
524 /**
525  * struct kdbus_cmd_ep_make - struct to make an endpoint
526  * @size:               The total size of the struct
527  * @flags:              Unused for now
528  * @items:              Items describing details such as the
529  *                      name of the endpoint
530  *
531  * This structure is used with the KDBUS_CMD_EP_MAKE ioctl.
532  */
533 struct kdbus_cmd_ep_make {
534         __u64 size;
535         __u64 flags;
536         struct kdbus_item items[0];
537 };
538
539 /**
540  * struct kdbus_cmd_ns_make - struct to make a namespace
541  * @size:               The total size of the struct
542  * @flags:              Unused for now
543  * @items:              Items describing details such as the
544  *                      name of the namespace
545  *
546  * This structure is used with the KDBUS_CMD_NS_MAKE ioctl.
547  */
548 struct kdbus_cmd_ns_make {
549         __u64 size;
550         __u64 flags;
551         struct kdbus_item items[0];
552 };
553
554 /**
555  * enum kdbus_name_flags - properties of a well-known name
556  * @KDBUS_NAME_REPLACE_EXISTING:        Try to replace name of other connections
557  * @KDBUS_NAME_ALLOW_REPLACEMENT:       Allow the replacement of the name
558  * @KDBUS_NAME_QUEUE:                   Name should be queued if busy
559  * @KDBUS_NAME_IN_QUEUE:                Name is queued
560  * @KDBUS_NAME_ACTIVATOR:               Name is owned by a activator connection
561  */
562 enum kdbus_name_flags {
563         KDBUS_NAME_REPLACE_EXISTING             = 1 <<  0,
564         KDBUS_NAME_ALLOW_REPLACEMENT            = 1 <<  1,
565         KDBUS_NAME_QUEUE                        = 1 <<  2,
566         KDBUS_NAME_IN_QUEUE                     = 1 <<  3,
567         KDBUS_NAME_ACTIVATOR                    = 1 <<  4,
568         KDBUS_NAME_STARTER_NAME                 = 1 <<  7,
569 };
570
571 /**
572  * struct kdbus_cmd_name - struct to describe a well-known name
573  * @size:               The total size of the struct
574  * @flags:              Flags for a name entry (KDBUS_NAME_*)
575  * @id:                 Privileged users may use this field to (de)register
576  *                      names on behalf of other peers.
577  * @conn_flags:         The flags of the owning connection (KDBUS_HELLO_*)
578  * @name:               The well-known name
579  *
580  * This structure is used with the KDBUS_CMD_NAME_ACQUIRE ioctl.
581  */
582 struct kdbus_cmd_name {
583         __u64 size;
584         __u64 flags;
585         __u64 id;
586         __u64 conn_flags;
587         char name[0];
588 };
589
590 /**
591  * enum kdbus_name_list_flags - what to include into the returned list
592  * @KDBUS_NAME_LIST_UNIQUE:     All active connections
593  * @KDBUS_NAME_LIST_NAMES:      All known well-known names
594  * @KDBUS_NAME_LIST_ACTIVATORS: All activator connections
595  * @KDBUS_NAME_LIST_QUEUED:     All queued-up names
596  */
597 enum kdbus_name_list_flags {
598         KDBUS_NAME_LIST_UNIQUE          = 1 <<  0,
599         KDBUS_NAME_LIST_NAMES           = 1 <<  1,
600         KDBUS_NAME_LIST_ACTIVATORS      = 1 <<  2,
601         KDBUS_NAME_LIST_QUEUED          = 1 <<  3,
602 };
603
604 /**
605  * struct kdbus_cmd_name_list - request a list of name entries
606  * @flags:              Flags for the query (KDBUS_NAME_LIST_*)
607  * @offset:             The returned offset in the caller's pool buffer.
608  *                      The user must use KDBUS_CMD_FREE to free the
609  *                      allocated memory.
610  *
611  * This structure is used with the KDBUS_CMD_NAME_LIST ioctl.
612  */
613 struct kdbus_cmd_name_list {
614         __u64 flags;
615         __u64 offset;
616 };
617
618 /**
619  * struct kdbus_name_list - information returned by KDBUS_CMD_NAME_LIST
620  * @size:               The total size of the structure
621  * @names:              A list of names
622  *
623  * Note that the user is responsible for freeing the allocated memory with
624  * the KDBUS_CMD_FREE ioctl.
625  */
626 struct kdbus_name_list {
627         __u64 size;
628         struct kdbus_cmd_name names[0];
629 };
630
631 /**
632  * struct kdbus_cmd_conn_info - struct used for KDBUS_CMD_CONN_INFO ioctl
633  * @size:               The total size of the struct
634  * @flags:              KDBUS_ATTACH_* flags
635  * @id:                 The 64-bit ID of the connection. If set to zero, passing
636  *                      @name is required. kdbus will look up the name to determine
637  *                      the ID in this case.
638  * @offset:             Returned offset in the caller's pool buffer where the
639  *                      kdbus_conn_info struct result is stored. The user must
640  *                      use KDBUS_CMD_FREE to free the allocated memory.
641  * @name:               The optional well-known name to look up. Only needed in
642  *                      case @id is zero.
643  *
644  * On success, the KDBUS_CMD_CONN_INFO ioctl will return 0 and @offset will
645  * tell the user the offset in the connection pool buffer at which to find the
646  * result in a struct kdbus_conn_info.
647  */
648 struct kdbus_cmd_conn_info {
649         __u64 size;
650         __u64 flags;
651         __u64 id;
652         __u64 offset;
653         char name[0];
654 };
655
656 /**
657  * struct kdbus_conn_info - information returned by KDBUS_CMD_CONN_INFO
658  * @size:               The total size of the struct
659  * @id:                 The connection's 64-bit ID
660  * @flags:              The connection's flags
661  * @items:              A list of struct kdbus_item
662  *
663  * Note that the user is responsible for freeing the allocated memory with
664  * the KDBUS_CMD_FREE ioctl.
665  */
666 struct kdbus_conn_info {
667         __u64 size;
668         __u64 id;
669         __u64 flags;
670         struct kdbus_item items[0];
671 };
672
673 /**
674  * enum kdbus_match_type - type of match record
675  * @KDBUS_MATCH_BLOOM:          Matches against KDBUS_MSG_BLOOM
676  * @KDBUS_MATCH_SRC_NAME:       Matches a name string
677  * @KDBUS_MATCH_NAME_ADD:       Matches a name string
678  * @KDBUS_MATCH_NAME_REMOVE:    Matches a name string
679  * @KDBUS_MATCH_NAME_CHANGE:    Matches a name string
680  * @KDBUS_MATCH_ID_ADD:         Matches an ID
681  * @KDBUS_MATCH_ID_REMOVE:      Matches an ID
682  */
683 enum kdbus_match_type {
684         _KDBUS_MATCH_NULL,
685         KDBUS_MATCH_BLOOM,
686         KDBUS_MATCH_SRC_NAME,
687         KDBUS_MATCH_NAME_ADD,
688         KDBUS_MATCH_NAME_REMOVE,
689         KDBUS_MATCH_NAME_CHANGE,
690         KDBUS_MATCH_ID_ADD,
691         KDBUS_MATCH_ID_REMOVE,
692 };
693
694 /**
695  * struct kdbus_cmd_match - struct to add or remove matches
696  * @size:               The total size of the struct
697  * @id:                 Privileged users may (de)register matches on behalf
698  *                      of other peers. In other cases, set to 0.
699  * @cookie:             Userspace supplied cookie. When removing, the cookie
700  *                      identifies the match to remove.
701  * @src_id:             The source ID to match against. Use
702  *                      KDBUS_MATCH_SRC_ID_ANY or any other value for a unique
703  *                      match.
704  * @items:              A list of items for additional information
705  *
706  * This structure is used with the KDBUS_CMD_ADD_MATCH and
707  * KDBUS_CMD_REMOVE_MATCH ioctl.
708  */
709 struct kdbus_cmd_match {
710         __u64 size;
711         __u64 id;
712         __u64 cookie;
713         __u64 src_id;
714         struct kdbus_item items[0];
715 };
716
717 /**
718  * enum kdbus_monitor_flags - flags for monitoring
719  * @KDBUS_MONITOR_ENABLE:       Enable monitoring
720  */
721 enum kdbus_monitor_flags {
722         KDBUS_MONITOR_ENABLE            = 1 <<  0,
723 };
724
725 /**
726  * struct kdbus_cmd_monitor - struct to enable or disable eavesdropping
727  * @id:                 Privileged users may enable or disable the monitor feature
728  *                      on behalf of other peers
729  * @flags:              Use KDBUS_MONITOR_ENABLE to enable eavesdropping
730  *
731  * This structure is used with the KDBUS_CMD_MONITOR ioctl.
732  */
733 struct kdbus_cmd_monitor {
734         __u64 id;
735         __u64 flags;
736 };
737
738 /**
739  * enum kdbus_ioctl_type - Ioctl API
740  * @KDBUS_CMD_BUS_MAKE:         After opening the "control" device node, this
741  *                              command creates a new bus with the specified
742  *                              name. The bus is immediately shut down and
743  *                              cleaned up when the opened "control" device node
744  *                              is closed.
745  * @KDBUS_CMD_NS_MAKE:          Similar to KDBUS_CMD_BUS_MAKE, but it creates a
746  *                              new kdbus namespace.
747  * @KDBUS_CMD_EP_MAKE:          Creates a new named special endpoint to talk to
748  *                              the bus. Such endpoints usually carry a more
749  *                              restrictive policy and grant restricted access
750  *                              to specific applications.
751  * @KDBUS_CMD_HELLO:            By opening the bus device node a connection is
752  *                              created. After a HELLO the opened connection
753  *                              becomes an active peer on the bus.
754  * @KDBUS_CMD_MSG_SEND:         Send a message and pass data from userspace to
755  *                              the kernel.
756  * @KDBUS_CMD_MSG_RECV:         Receive a message from the kernel which is
757  *                              placed in the receiver's pool.
758  * @KDBUS_CMD_FREE:             Release the allocated memory in the receiver's
759  *                              pool.
760  * @KDBUS_CMD_NAME_ACQUIRE:     Request a well-known bus name to associate with
761  *                              the connection. Well-known names are used to
762  *                              address a peer on the bus.
763  * @KDBUS_CMD_NAME_RELEASE:     Release a well-known name the connection
764  *                              currently owns.
765  * @KDBUS_CMD_NAME_LIST:        Retrieve the list of all currently registered
766  *                              well-known and unique names.
767  * @KDBUS_CMD_CONN_INFO:        Retrieve credentials and properties of the
768  *                              initial creator of the connection. The data was
769  *                              stored at registration time and does not
770  *                              necessarily represent the connected process or
771  *                              the actual state of the process.
772  * @KDBUS_CMD_MATCH_ADD:        Install a match which broadcast messages should
773  *                              be delivered to the connection.
774  * @KDBUS_CMD_MATCH_REMOVE:     Remove a current match for broadcast messages.
775  * @KDBUS_CMD_MONITOR:          Monitor the bus and receive all transmitted
776  *                              messages. Privileges are required for this
777  *                              operation.
778  * @KDBUS_CMD_EP_POLICY_SET:    Set the policy of an endpoint. It is used to
779  *                              restrict the access for endpoints created with
780  *                              KDBUS_CMD_EP_MAKE.
781  * @KDBUS_CMD_MEMFD_NEW:        Return a new file descriptor which provides an
782  *                              anonymous shared memory file and which can be
783  *                              used to pass around larger chunks of data.
784  *                              Kdbus memfd files can be sealed, which allows
785  *                              the receiver to trust the data it has received.
786  *                              Kdbus memfd files expose only very limited
787  *                              operations, they can be mmap()ed, seek()ed,
788  *                              (p)read(v)() and (p)write(v)(); most other
789  *                              common file operations are not implemented.
790  *                              Special caution needs to be taken with
791  *                              read(v)()/write(v)() on a shared file; the
792  *                              underlying file position is always shared
793  *                              between all users of the file and race against
794  *                              each other, pread(v)()/pwrite(v)() avoid these
795  *                              issues.
796  * @KDBUS_CMD_MEMFD_SIZE_GET:   Return the size of the underlying file, which
797  *                              changes with write().
798  * @KDBUS_CMD_MEMFD_SIZE_SET:   Truncate the underlying file to the specified
799  *                              size.
800  * @KDBUS_CMD_MEMFD_SEAL_GET:   Return the state of the file sealing.
801  * @KDBUS_CMD_MEMFD_SEAL_SET:   Seal or break a seal of the file. Only files
802  *                              which are not shared with other processes and
803  *                              which are currently not mapped can be sealed.
804  *                              The current process needs to be the one and
805  *                              single owner of the file, the sealing cannot
806  *                              be changed as long as the file is shared.
807  */
808 enum kdbus_ioctl_type {
809         KDBUS_CMD_BUS_MAKE =            _IOW (KDBUS_IOC_MAGIC, 0x00, struct kdbus_cmd_bus_make),
810         KDBUS_CMD_NS_MAKE =             _IOR (KDBUS_IOC_MAGIC, 0x10, struct kdbus_cmd_ns_make),
811
812         KDBUS_CMD_EP_MAKE =             _IOW (KDBUS_IOC_MAGIC, 0x20, struct kdbus_cmd_ep_make),
813         KDBUS_CMD_HELLO =               _IOWR(KDBUS_IOC_MAGIC, 0x30, struct kdbus_cmd_hello),
814
815         KDBUS_CMD_MSG_SEND =            _IOW (KDBUS_IOC_MAGIC, 0x40, struct kdbus_msg),
816         KDBUS_CMD_MSG_RECV =            _IOR (KDBUS_IOC_MAGIC, 0x41, __u64 *),
817         KDBUS_CMD_FREE =                _IOW (KDBUS_IOC_MAGIC, 0x42, __u64 *),
818
819         KDBUS_CMD_NAME_ACQUIRE =        _IOWR(KDBUS_IOC_MAGIC, 0x50, struct kdbus_cmd_name),
820         KDBUS_CMD_NAME_RELEASE =        _IOW (KDBUS_IOC_MAGIC, 0x51, struct kdbus_cmd_name),
821         KDBUS_CMD_NAME_LIST =           _IOWR(KDBUS_IOC_MAGIC, 0x52, struct kdbus_cmd_name_list),
822         KDBUS_CMD_NAME_LIST_QUEUED = _IOWR(KDBUS_IOC_MAGIC, 0x58, struct kdbus_cmd_conn_info),
823
824         KDBUS_CMD_CONN_INFO =           _IOWR(KDBUS_IOC_MAGIC, 0x60, struct kdbus_cmd_conn_info),
825
826         KDBUS_CMD_MATCH_ADD =           _IOW (KDBUS_IOC_MAGIC, 0x70, struct kdbus_cmd_match),
827         KDBUS_CMD_MATCH_REMOVE =        _IOW (KDBUS_IOC_MAGIC, 0x71, struct kdbus_cmd_match),
828         KDBUS_CMD_MONITOR =             _IOW (KDBUS_IOC_MAGIC, 0x72, struct kdbus_cmd_monitor),
829
830         KDBUS_CMD_EP_POLICY_SET =       _IOW (KDBUS_IOC_MAGIC, 0x80, struct kdbus_cmd_policy),
831
832         KDBUS_CMD_MEMFD_NEW =           _IOR (KDBUS_IOC_MAGIC, 0x90, int *),
833         KDBUS_CMD_MEMFD_SIZE_GET =      _IOR (KDBUS_IOC_MAGIC, 0x91, __u64 *),
834         KDBUS_CMD_MEMFD_SIZE_SET =      _IOW (KDBUS_IOC_MAGIC, 0x92, __u64 *),
835         KDBUS_CMD_MEMFD_SEAL_GET =      _IOR (KDBUS_IOC_MAGIC, 0x93, int *),
836         KDBUS_CMD_MEMFD_SEAL_SET =      _IO  (KDBUS_IOC_MAGIC, 0x94),
837 };
838
839 #ifdef KDBUS_FOR_SBB
840 #define SBB_AGENT_ID_MASK               ((__u64)1 << 63)
841 //FIXME KDBUS_DST_ID_BROADCAST has "remote" mask
842 #endif
843
844 /*
845  * errno - api error codes
846  * @E2BIG:              A message contains too many records or items.
847  * @EADDRINUSE:         A well-known bus name is already taken by another
848  *                      connection.
849  * @EADDRNOTAVAIL:      A message flagged not to activate a service, addressed
850  *                      a service which is not currently running.
851  * @EAGAIN:             No messages are queued at the moment.
852  * @EBADF:              File descriptors passed with the message are not valid.
853  * @EBADFD:             A bus connection is in a corrupted state.
854  * @EBADMSG:            Passed data contains a combination of conflicting or
855  *                      inconsistent types.
856  * @ECONNRESET:         A connection is shut down, no further operations are
857  *                      possible.
858  * @ECOMM:              A peer does not accept the file descriptors addressed
859  *                      to it.
860  * @EDESTADDRREQ:       The well-known bus name is required but missing.
861  * @EDOM:               The size of data does not match the expectations. Used
862  *                      for the size of the bloom filter bit field.
863  * @EEXIST:             A requested namespace, bus or endpoint with the same
864  *                      name already exists.  A specific data type, which is
865  *                      only expected once, is provided multiple times.
866  * @EFAULT:             The supplied memory could not be accessed, or the data
867  *                      is not properly aligned.
868  * @EINVAL:             The provided data does not match its type or other
869  *                      expectations, like a string which is not NUL terminated,
870  *                      or a string length that points behind the first
871  *                      \0-byte in the string.
872  * @EMEDIUMTYPE:        A file descriptor which is not a kdbus memfd was
873  *                      refused to send as KDBUS_MSG_PAYLOAD_MEMFD.
874  * @EMFILE:             Too many file descriptors have been supplied with a
875  *                      message.
876  * @EMSGSIZE:           The supplied data is larger than the allowed maximum
877  *                      size.
878  * @ENAMETOOLONG:       The requested name is larger than the allowed maximum
879  *                      size.
880  * @ENOBUFS:            There is no space left for the submitted data to fit
881  *                      into the receiver's pool.
882  * @ENOMEM:             Out of memory.
883  * @ENOSYS:             The requested functionality is not available.
884  * @ENOTCONN:           The addressed peer is not an active connection.
885  * @ENOTSUPP:           The feature negotiation failed, a not supported feature
886  *                      was requested, or an unknown item type was received.
887  * @ENOTTY:             An unknown ioctl command was received.
888  * @ENOTUNIQ:           A specific data type was addressed to a broadcast
889  *                      address, but only direct addresses support this kind of
890  *                      data.
891  * @ENXIO:              A unique address does not exist.
892  * @EPERM:              The policy prevented an operation. The requested
893  *                      resource is owned by another entity.
894  * @ESHUTDOWN:          A namespace or endpoint is currently shutting down;
895  *                      no further operations will be possible.
896  * @ESRCH:              A requested well-known bus name is not found.
897  * @ETXTBSY:            A kdbus memfd file cannot be sealed or the seal removed,
898  *                      because it is shared with other processes or still
899  *                      mmap()ed.
900  * @EXFULL:             The size limits in the pool are reached, no data of
901  *                      the size tried to submit can be queued.
902  */
903 #endif