bus: Assign a serial number for messages from the driver
[platform/upstream/dbus.git] / dbus / kdbus-common.h
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* kdbus-common.h  kdbus related utils for daemon and libdbus
3  *
4  * Copyright (C) 2013  Samsung Electronics
5  *
6  * Licensed under the Academic Free License version 2.1
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version and under the terms of the GNU
12  * Lesser General Public License as published by the
13  * Free Software Foundation; either version 2.1 of the License, or (at
14  * your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24  *
25  */
26
27 #ifndef KDBUS_COMMON_H_
28 #define KDBUS_COMMON_H_
29
30 #include <dbus/dbus-types.h>
31 #include <dbus/dbus-transport.h>
32 #include "dbus-signals.h"
33 #include <linux/kdbus.h>
34 #include <stdint.h>
35
36 #define KDBUS_ALIGN8(l) (((l) + 7) & ~7)
37
38 #define KDBUS_ITEM_HEADER_SIZE          offsetof(struct kdbus_item, data)
39 #define KDBUS_ITEM_SIZE(s) KDBUS_ALIGN8(KDBUS_ITEM_HEADER_SIZE + (s))
40 #define KDBUS_ITEM_NEXT_ADDRESS(item) ((uintptr_t)(((uint8_t *)item) + KDBUS_ALIGN8((item)->size)))
41 #define KDBUS_ITEM_NEXT(item) \
42         (typeof(item))KDBUS_ITEM_NEXT_ADDRESS(item)
43 #define KDBUS_ITEM_FOREACH(item, head, first)                           \
44         for (item = (head)->first;                                      \
45              (uint8_t *)(item) < (uint8_t *)(head) + (head)->size;      \
46              item = KDBUS_ITEM_NEXT(item))
47
48 #define KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE  0x00200000              /* maximum size of message header and items */
49
50 struct nameInfo
51 {
52   __u64 uniqueId;
53   __u64 flags;
54   __u64 userId;
55   __u64 processId;
56   __u32 sec_label_len;
57   char *sec_label;
58 };
59
60 typedef struct kdbus_t kdbus_t;
61
62 typedef __u64 kdbus_bloom_data_t;
63
64 kdbus_t *   _kdbus_new                             (const char *path);
65 void        _kdbus_free                            (kdbus_t *kdbus);
66
67 int         _kdbus_open                            (kdbus_t *kdbus);
68 int         _kdbus_close                           (kdbus_t *kdbus);
69
70 void       *_kdbus_get_pool                        (kdbus_t *kdbus);
71 const char *_kdbus_get_path                        (kdbus_t *kdbus);
72 int         _kdbus_get_fd                          (kdbus_t *kdbus);
73 __u64       _kdbus_get_id                          (kdbus_t *kdbus);
74 char       *_kdbus_get_bus_id                      (kdbus_t *kdbus);
75 __u64       _kdbus_get_bus_id_size                 (void);
76
77 int         _kdbus_hello                           (kdbus_t       *kdbus,
78                                                     __u64          flags,
79                                                     __u64          attach_flags_send,
80                                                     __u64          attach_flags_recv,
81                                                     __u64          pool_size,
82                                                     const char    *activator_name,
83                                                     const char    *connection_name);
84
85 int         _kdbus_send                            (kdbus_t           *kdbus,
86                                                     __u64              flags,
87                                                     struct kdbus_msg  *msg,
88                                                     struct kdbus_msg **msg_reply);
89
90 int         _kdbus_recv                            (kdbus_t           *kdbus,
91                                                     __u64              flags,
92                                                     __s64              priority,
93                                                     struct kdbus_msg **msg);
94
95 int         _kdbus_list                            (kdbus_t            *kdbus,
96                                                     __u64               flags,
97                                                     struct kdbus_info **name_list,
98                                                     __u64              *list_size);
99
100 int         _kdbus_add_match_name_acquired         (kdbus_t *kdbus,
101                                                     __u64    flags,
102                                                     __u64    cookie,
103                                                     __u64    old_id,
104                                                     __u64    old_id_flags,
105                                                     __u64    new_id,
106                                                     __u64    new_id_flags,
107                                                     const char *name);
108
109 int         _kdbus_add_match_name_lost             (kdbus_t *kdbus,
110                                                     __u64    flags,
111                                                     __u64    cookie,
112                                                     __u64    old_id,
113                                                     __u64    old_id_flags,
114                                                     __u64    new_id,
115                                                     __u64    new_id_flags,
116                                                     const char *name);
117
118 int         _kdbus_add_match_name_change           (kdbus_t *kdbus,
119                                                     __u64    flags,
120                                                     __u64    cookie,
121                                                     __u64    old_id,
122                                                     __u64    old_id_flags,
123                                                     __u64    new_id,
124                                                     __u64    new_id_flags,
125                                                     const char *name);
126
127 int         _kdbus_add_match_id_change             (kdbus_t *kdbus,
128                                                     __u64    flags,
129                                                     __u64    cookie,
130                                                     __u64    id,
131                                                     __u64    id_flags,
132                                                     const char *name);
133
134 int         _kdbus_add_match                      (kdbus_t                *kdbus,
135                                                    struct kdbus_cmd_match *cmd);
136
137 int         _kdbus_connection_info_by_name         (kdbus_t         *kdbus,
138                                                     const char      *name,
139                                                     dbus_bool_t      get_sec_label,
140                                                     struct nameInfo *pInfo);
141
142 int         _kdbus_connection_info_by_id           (kdbus_t         *kdbus,
143                                                     __u64            id,
144                                                     dbus_bool_t      get_sec_label,
145                                                     struct nameInfo *pInfo);
146
147 __u64       _kdbus_compute_msg_items_size          (kdbus_t       *kdbus,
148                                                     const char    *destination,
149                                                     __u64          dst_id,
150                                                     __u64          body_size,
151                                                     dbus_bool_t    use_memfd,
152                                                     int            fds_count);
153
154 struct kdbus_msg * _kdbus_new_msg                  (kdbus_t                *kdbus,
155                                                     __u64                   size_for_items,
156                                                     __u64                   flags,
157                                                     __s64                   priority,
158                                                     __u64                   dst_id,
159                                                     __u64                   src_id,
160                                                     enum kdbus_payload_type payload_type,
161                                                     __u64                   cookie,
162                                                     __u64                   timeout_ns_or_cookie_reply);
163
164 void               _kdbus_free_msg                 (struct kdbus_msg *msg);
165
166 __u64              _kdbus_compute_match_items_size (kdbus_t       *kdbus,
167                                                     dbus_bool_t    with_bloom_mask,
168                                                     __u64          sender_id,
169                                                     const char    *sender_name);
170
171 struct kdbus_cmd_match *_kdbus_new_cmd_match       (kdbus_t       *kdbus,
172                                                     __u64          items_size,
173                                                     __u64          flags,
174                                                     __u64          cookie);
175
176 void               _kdbus_free_cmd_match           (struct kdbus_cmd_match *cmd);
177
178 int                _kdbus_free_mem                 (kdbus_t *kdbus, void *mem);
179
180 struct kdbus_item * _kdbus_item_add_string         (struct kdbus_item *item,
181                                                     __u64              item_type,
182                                                     const char        *item_string,
183                                                     __u64              item_string_size);
184
185 struct kdbus_item * _kdbus_item_add_payload_memfd  (struct kdbus_item *item,
186                                                     __u64              start,
187                                                     __u64              size,
188                                                     int                fd);
189
190 struct kdbus_item * _kdbus_item_add_payload_vec    (struct kdbus_item *item,
191                                                     __u64              size,
192                                                     __u64              address_or_offset);
193
194 struct kdbus_item * _kdbus_item_add_fds            (struct kdbus_item *item,
195                                                     const int         *fds,
196                                                     int                fds_count);
197
198 struct kdbus_item * _kdbus_item_add_bloom_filter   (struct kdbus_item          *item,
199                                                     kdbus_t                    *kdbus,
200                                                     struct kdbus_bloom_filter **out_ptr);
201
202 kdbus_bloom_data_t *_kdbus_bloom_filter_get_data   (struct kdbus_bloom_filter *bloom_filter);
203
204 struct kdbus_item * _kdbus_item_add_name_change    (struct kdbus_item *item,
205                                                     __u64              old_id,
206                                                     __u64              old_id_flags,
207                                                     __u64              new_id,
208                                                     __u64              new_id_flags);
209
210 struct kdbus_item * _kdbus_item_add_id_add         (struct kdbus_item *item,
211                                                     __u64              id,
212                                                     __u64              id_flags);
213
214 struct kdbus_item * _kdbus_item_add_id             (struct kdbus_item *item,
215                                                     __u64              id);
216
217 struct kdbus_item * _kdbus_item_add_bloom_mask     (struct kdbus_item   *item,
218                                                     kdbus_t             *kdbus,
219                                                     kdbus_bloom_data_t **bloom);
220
221 int         _kdbus_request_name                    (kdbus_t *kdbus,
222                                                     const char *name,
223                                                     const __u64 flags);
224 int         _kdbus_release_name                    (kdbus_t *kdbus,
225                                                     const char *name);
226
227 int         _kdbus_remove_match                    (kdbus_t    *kdbus,
228                                                     __u64       cookie);
229
230 void        _kdbus_bloom_add_data                  (kdbus_t            *kdbus,
231                                                     kdbus_bloom_data_t *bloom_data,
232                                                     const void         *data,
233                                                     size_t              data_size);
234 #endif /* KDBUS_COMMON_H_ */