Monado OpenXR Runtime
os_ble_dbus.c File Reference

BLE implementation based on Linux Bluez/dbus. More...

#include "os_ble.h"
#include "util/u_misc.h"
#include "util/u_logging.h"
#include <poll.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <dbus/dbus.h>
Include dependency graph for os_ble_dbus.c:

Data Structures

struct  ble_conn_helper
 Small helper that keeps track of a connection and a error. More...
 
struct  ble_notify
 An implementation of os_ble_device using a DBus connection to BlueZ. More...
 

Macros

#define I(bch, ...)   U_LOG_I(__VA_ARGS__)
 
#define E(bch, ...)   U_LOG_E(__VA_ARGS__)
 
#define for_each(i, first)
 

Functions

static void add_single_byte_array (DBusMessage *msg, uint8_t value)
 
static void add_empty_dict_sv (DBusMessage *msg)
 
static int send_message (DBusConnection *conn, DBusError *err, DBusMessage **msg_ptr)
 
static void dump_recurse (DBusMessageIter *parent, DBusMessageIter *sub, int level)
 
static int dump_one_element (DBusMessageIter *element, int level)
 
static bool starts_with_and_has_slash (const char *str, const char *beginning)
 Checks if a string starts with, has extra slash and room for more. More...
 
static int dict_get_string_and_varient_child (DBusMessageIter *dict, const char **out_str, DBusMessageIter *out_child)
 
static int dict_get_string_and_array_elm (const DBusMessageIter *in_dict, const char **out_str, DBusMessageIter *out_array_elm)
 
static int array_get_first_elem_of_type (const DBusMessageIter *in_parent, int of_type, DBusMessageIter *out_elm)
 Ensures that the parent is a array and has a element type the given type, outputs the first element of the array on success. More...
 
static int array_find_variant_value (const DBusMessageIter *first_elm, const char *key, DBusMessageIter *out_value)
 Given a the first element in a array of dict, loop over them and check if the key matches its string value. More...
 
static int array_match_string_element (const DBusMessageIter *in_array, const char *key)
 Given a array which elements are of type string, loop over them and check if any of them matches the given key. More...
 
static int dbus_has_name (DBusConnection *conn, const char *name)
 
static int device_has_uuid (const DBusMessageIter *dict, const char *uuid, const char **out_path_str)
 Returns true if the object implements the org.bluez.Device1 interface, and one of its UUIDs matches the given uuid. More...
 
static int gatt_iface_get_flag_notifiable (const DBusMessageIter *iface_elm, bool *out_bool)
 On a gatt interface object get its Flags property and check if notify is set, returns positive if it found that Flags property, zero on not finding it and negative on error. More...
 
static int gatt_iface_get_uuid (const DBusMessageIter *iface_elm, const char **out_str)
 On a gatt interface object get its UUID string property, returns positive if found, zero on not finding it and negative on error. More...
 
static int gatt_char_has_uuid (const DBusMessageIter *dict, const char *uuid, const char **out_path_str, bool *out_notifiable)
 Returns positive value if the object implements the org.bluez.GattCharacteristic1 interface, its UUID matches the given uuid. More...
 
static void ble_close (struct ble_conn_helper *bch)
 
static int ble_init (struct ble_conn_helper *bch)
 
static int ble_dbus_send (struct ble_conn_helper *bch, DBusMessage **out_msg)
 
static int ble_get_managed_objects (struct ble_conn_helper *bch, DBusMessage **out_msg)
 
static int ble_connect (struct ble_conn_helper *bch, const char *dbus_address)
 
static int ble_connect_all_devices_with_service_uuid (struct ble_conn_helper *bch, const char *service_uuid)
 
static int ble_write_value (struct ble_conn_helper *bch, const char *dbus_address, uint8_t value)
 
static ssize_t get_path_to_notify_char (struct ble_conn_helper *bch, const char *dev_uuid, const char *char_uuid, char *output, size_t output_len)
 
static int init_ble_notify (const char *dev_uuid, const char *char_uuid, struct ble_notify *bledev)
 
static int os_ble_notify_read (struct os_ble_device *bdev, uint8_t *data, size_t length, int milliseconds)
 
static void os_ble_notify_destroy (struct os_ble_device *bdev)
 
int os_ble_notify_open (const char *dev_uuid, const char *char_uuid, struct os_ble_device **out_ble)
 Returns a notification endpoint from the given device uuid and char uuid. More...
 
int os_ble_broadcast_write_value (const char *service_uuid, const char *char_uuid, uint8_t value)
 Returns write startpoints from the given device uuid and char uuid. More...
 

Detailed Description

BLE implementation based on Linux Bluez/dbus.

Author
Pete Black pete..nosp@m.blac.nosp@m.k@col.nosp@m.labo.nosp@m.ra.co.nosp@m.m
Jakob Bornecrantz jakob.nosp@m.@col.nosp@m.labor.nosp@m.a.co.nosp@m.m

Macro Definition Documentation

◆ for_each

#define for_each (   i,
  first 
)
Value:
for (DBusMessageIter i = first; dbus_message_iter_get_arg_type(&i) != DBUS_TYPE_INVALID; \
dbus_message_iter_next(&i))

Function Documentation

◆ array_find_variant_value()

static int array_find_variant_value ( const DBusMessageIter *  first_elm,
const char *  key,
DBusMessageIter *  out_value 
)
static

Given a the first element in a array of dict, loop over them and check if the key matches its string value.

Returns positive if a match is found, zero if not found and negative on failure. The argument out_value holds the value of the dict pair.

◆ array_get_first_elem_of_type()

static int array_get_first_elem_of_type ( const DBusMessageIter *  in_parent,
int  of_type,
DBusMessageIter *  out_elm 
)
static

Ensures that the parent is a array and has a element type the given type, outputs the first element of the array on success.

◆ array_match_string_element()

static int array_match_string_element ( const DBusMessageIter *  in_array,
const char *  key 
)
static

Given a array which elements are of type string, loop over them and check if any of them matches the given key.

Returns positive if a match is found, zero if not found and negative on failure.

◆ device_has_uuid()

static int device_has_uuid ( const DBusMessageIter *  dict,
const char *  uuid,
const char **  out_path_str 
)
static

Returns true if the object implements the org.bluez.Device1 interface, and one of its UUIDs matches the given uuid.

◆ gatt_char_has_uuid()

static int gatt_char_has_uuid ( const DBusMessageIter *  dict,
const char *  uuid,
const char **  out_path_str,
bool out_notifiable 
)
static

Returns positive value if the object implements the org.bluez.GattCharacteristic1 interface, its UUID matches the given uuid.

◆ gatt_iface_get_flag_notifiable()

static int gatt_iface_get_flag_notifiable ( const DBusMessageIter *  iface_elm,
bool out_bool 
)
static

On a gatt interface object get its Flags property and check if notify is set, returns positive if it found that Flags property, zero on not finding it and negative on error.

◆ gatt_iface_get_uuid()

static int gatt_iface_get_uuid ( const DBusMessageIter *  iface_elm,
const char **  out_str 
)
static

On a gatt interface object get its UUID string property, returns positive if found, zero on not finding it and negative on error.

◆ starts_with_and_has_slash()

static bool starts_with_and_has_slash ( const char *  str,
const char *  beginning 
)
static

Checks if a string starts with, has extra slash and room for more.