1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* kdbus-common.h kdbus related utils for daemon and libdbus
4 * Copyright (C) 2013 Samsung Electronics
6 * Licensed under the Academic Free License version 2.1
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.
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.
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
27 #ifndef KDBUS_COMMON_H_
28 #define KDBUS_COMMON_H_
30 #include <dbus/dbus-types.h>
31 #include <dbus/dbus-transport.h>
32 #include "dbus-signals.h"
33 #include <linux/kdbus.h>
36 #define KDBUS_ALIGN8(l) (((l) + 7) & ~7)
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))
48 #define KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE 0x00200000 /* maximum size of message header and items */
60 typedef struct kdbus_t kdbus_t;
62 typedef __u64 kdbus_bloom_data_t;
64 kdbus_t * _kdbus_new (const char *path);
65 void _kdbus_free (kdbus_t *kdbus);
67 int _kdbus_open (kdbus_t *kdbus);
68 int _kdbus_close (kdbus_t *kdbus);
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);
77 int _kdbus_hello (kdbus_t *kdbus,
79 __u64 attach_flags_send,
80 __u64 attach_flags_recv,
82 const char *activator_name,
83 const char *connection_name);
85 int _kdbus_send (kdbus_t *kdbus,
87 struct kdbus_msg *msg,
88 struct kdbus_msg **msg_reply);
90 int _kdbus_recv (kdbus_t *kdbus,
93 struct kdbus_msg **msg);
95 int _kdbus_list (kdbus_t *kdbus,
97 struct kdbus_info **name_list,
100 int _kdbus_add_match_name_acquired (kdbus_t *kdbus,
109 int _kdbus_add_match_name_lost (kdbus_t *kdbus,
118 int _kdbus_add_match_name_change (kdbus_t *kdbus,
127 int _kdbus_add_match_id_change (kdbus_t *kdbus,
134 int _kdbus_add_match (kdbus_t *kdbus,
135 struct kdbus_cmd_match *cmd);
137 int _kdbus_connection_info_by_name (kdbus_t *kdbus,
139 dbus_bool_t get_sec_label,
140 struct nameInfo *pInfo);
142 int _kdbus_connection_info_by_id (kdbus_t *kdbus,
144 dbus_bool_t get_sec_label,
145 struct nameInfo *pInfo);
147 __u64 _kdbus_compute_msg_items_size (kdbus_t *kdbus,
148 const char *destination,
151 dbus_bool_t use_memfd,
154 struct kdbus_msg * _kdbus_new_msg (kdbus_t *kdbus,
155 __u64 size_for_items,
160 enum kdbus_payload_type payload_type,
162 __u64 timeout_ns_or_cookie_reply);
164 void _kdbus_free_msg (struct kdbus_msg *msg);
166 __u64 _kdbus_compute_match_items_size (kdbus_t *kdbus,
167 dbus_bool_t with_bloom_mask,
169 const char *sender_name);
171 struct kdbus_cmd_match *_kdbus_new_cmd_match (kdbus_t *kdbus,
176 void _kdbus_free_cmd_match (struct kdbus_cmd_match *cmd);
178 int _kdbus_free_mem (kdbus_t *kdbus, void *mem);
180 struct kdbus_item * _kdbus_item_add_string (struct kdbus_item *item,
182 const char *item_string,
183 __u64 item_string_size);
185 struct kdbus_item * _kdbus_item_add_payload_memfd (struct kdbus_item *item,
190 struct kdbus_item * _kdbus_item_add_payload_vec (struct kdbus_item *item,
192 __u64 address_or_offset);
194 struct kdbus_item * _kdbus_item_add_fds (struct kdbus_item *item,
198 struct kdbus_item * _kdbus_item_add_bloom_filter (struct kdbus_item *item,
200 struct kdbus_bloom_filter **out_ptr);
202 kdbus_bloom_data_t *_kdbus_bloom_filter_get_data (struct kdbus_bloom_filter *bloom_filter);
204 struct kdbus_item * _kdbus_item_add_name_change (struct kdbus_item *item,
210 struct kdbus_item * _kdbus_item_add_id_add (struct kdbus_item *item,
214 struct kdbus_item * _kdbus_item_add_id (struct kdbus_item *item,
217 struct kdbus_item * _kdbus_item_add_bloom_mask (struct kdbus_item *item,
219 kdbus_bloom_data_t **bloom);
221 int _kdbus_request_name (kdbus_t *kdbus,
224 int _kdbus_release_name (kdbus_t *kdbus,
227 int _kdbus_remove_match (kdbus_t *kdbus,
230 void _kdbus_bloom_add_data (kdbus_t *kdbus,
231 kdbus_bloom_data_t *bloom_data,
234 #endif /* KDBUS_COMMON_H_ */