_bt_common_event_cb(BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED,
result, ¶ms, event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_PXP_PROPERTY_CHANGED) == 0) {
+ const char *address = NULL;
+ bluetooth_device_address_t dev_address = { {0} };
+ int role, type, level;
+ bt_pxp_property_changed_params_t params;
+
+ BT_DBG("BT_PXP_PROPERTY_CHANGED");
+
+ g_variant_get(parameters, "(isiii)", &result, &address, &role, &type, &level);
+
+ _bt_convert_addr_string_to_type(dev_address.addr, address);
+ memcpy(¶ms.device_address, &dev_address, BLUETOOTH_ADDRESS_LENGTH);
+ params.role = role;
+ params.service_type = type;
+ params.alert_lvl = level;
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED,
+ result, ¶ms, event_info->cb, event_info->user_data);
}
}
return result;
}
+
+BT_EXPORT_API int bluetooth_register_proximity_reporter()
+{
+ int result = BLUETOOTH_ERROR_INTERNAL;
+
+ BT_CHECK_ENABLED(return);
+
+ BT_INIT_PARAMS();
+ BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+ BT_DBG("");
+
+ result = _bt_send_request(BT_BLUEZ_SERVICE, BT_PXP_REGISTER_REPORTER,
+ in_param1, in_param2, in_param3, in_param4, &out_param);
+
+ BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+ return result;
+}
+
+BT_EXPORT_API int bluetooth_unregister_proximity_reporter()
+{
+ int result = BLUETOOTH_ERROR_INTERNAL;
+
+ BT_CHECK_ENABLED(return);
+
+ BT_INIT_PARAMS();
+ BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+ BT_DBG("");
+
+ result = _bt_send_request(BT_BLUEZ_SERVICE, BT_PXP_UNREGISTER_REPORTER,
+ in_param1, in_param2, in_param3, in_param4, &out_param);
+
+ BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+ return result;
+}
}
break;
}
+ case BT_PXP_REGISTER_REPORTER: {
+ result = bt_register_proximity_reporter();
+ break;
+ }
+ case BT_PXP_UNREGISTER_REPORTER: {
+ result = bt_unregister_proximity_reporter();
+ break;
+ }
default:
result = BLUETOOTH_ERROR_INTERNAL;
break;
case BT_PXP_SET_PROPERTY:
case BT_PXP_GET_PROPERTY:
case BT_PXP_GET_SUPPORTED_SERIVCES:
+ case BT_PXP_REGISTER_REPORTER:
+ case BT_PXP_UNREGISTER_REPORTER:
ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
BT_PRIVILEGE_PLATFORM);
#include "bt-service-headset-connection.h"
#include "bt-service-avrcp-controller.h"
#include "bt-service-hid.h"
+#include "bt-service-proximity.h"
#include "bt-service-opp-client.h"
BT_DBG("-");
}
+int get_alert_level_enum(const char *alert)
+{
+ int lvl = -1;
+
+ if (strcmp(alert, "none") == 0)
+ lvl = BT_PXP_ALERT_NONE;
+ else if (strcmp(alert, "mild") == 0)
+ lvl = BT_PXP_ALERT_MILD;
+ else if (strcmp(alert, "high") == 0)
+ lvl = BT_PXP_ALERT_HIGH;
+
+ return lvl;
+}
+
+static void _bt_handle_pxp_property_changed_event(GVariant *msg, const char *path, int role)
+{
+ int result = BLUETOOTH_ERROR_NONE;
+ int service_type;
+ int alert_lvl;
+ GVariantIter value_iter;
+ char *property = NULL;
+ char *address;
+ GVariant *val = NULL;
+ GVariant *child = NULL;
+ GVariant *param = NULL;
+ g_variant_iter_init(&value_iter, msg);
+
+ BT_DBG("+");
+ while ((child = g_variant_iter_next_value(&value_iter))) {
+ g_variant_get(child, "{sv}", &property, &val);
+ BT_INFO("Property %s", property);
+
+ if ((strcasecmp(property, "LinkLossAlertLevel") == 0) ||
+ (strcasecmp(property, "ImmediateAlertLevel") == 0)) {
+ char *alert_str = NULL;
+
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+ _bt_convert_device_path_to_address(path, address);
+
+ if (strcasecmp(property, "LinkLossAlertLevel") == 0)
+ service_type = BT_PXP_PROPERTY_LLS;
+ else
+ service_type = BT_PXP_PROPERTY_IAS;
+
+ g_variant_get(val, "s", &alert_str);
+ alert_lvl = get_alert_level_enum(alert_str);
+
+ param = g_variant_new("(isiii)", result, address,
+ role, service_type, alert_lvl);
+
+ /* Send event to application */
+ _bt_send_event(BT_DEVICE_EVENT,
+ BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED,
+ param);
+ g_free(address);
+ g_free(alert_str);
+ }
+ g_free(property);
+ g_variant_unref(child);
+ g_variant_unref(val);
+ }
+ BT_DBG("-");
+}
+
void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
{
char *interface_name = NULL;
} else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
__bt_gatt_char_property_changed_event(val,
object_path);
+ } else if (strcasecmp(interface_name, BT_PROXIMITY_REPORTER_INTERFACE) == 0) {
+ BT_DBG("BT_PROXIMITY_REPORTER_INTERFACE");
+ _bt_handle_pxp_property_changed_event(val,
+ object_path, BT_PXP_REPORTER_ROLE);
}
g_variant_unref(val);
}
break;
case BLUETOOTH_EVENT_REMOTE_IBEACON_DEVICE_FOUND:
signal = BT_IBEACON_DEVICE_FOUND;
+ case BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED:
+ signal = BT_PXP_PROPERTY_CHANGED;
break;
default:
BT_ERR("Unknown event");
return BLUETOOTH_ERROR_NONE;
}
+
+int bt_register_proximity_reporter()
+{
+ GDBusProxy *proxy;
+
+ GDBusConnection *conn;
+ char *adapter_path = NULL;
+ GError *error = NULL;
+ GVariant *result = NULL;
+
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ adapter_path = _bt_get_adapter_path();
+ if (adapter_path == NULL) {
+ BT_ERR("Could not get adapter path\n");
+ return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
+ }
+
+ BT_INFO("Adapter path %s", adapter_path);
+
+ proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME, adapter_path,
+ BT_PROXIMITY_REPORTER_INTERFACE, NULL, NULL);
+
+ g_free(adapter_path);
+ retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ result = g_dbus_proxy_call_sync(proxy, "RegisterProximity",
+ NULL, G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL, &error);
+ if (result == NULL) {
+ if (error != NULL) {
+ BT_ERR("Error occured in Proxy call [%s]\n", error->message);
+ g_error_free(error);
+ }
+ g_object_unref(proxy);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+ g_object_unref(proxy);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int bt_unregister_proximity_reporter()
+{
+ GDBusProxy *proxy;
+
+ GDBusConnection *conn;
+ char *adapter_path = NULL;
+ GError *error = NULL;
+ GVariant *result = NULL;
+
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ adapter_path = _bt_get_adapter_path();
+ if (adapter_path == NULL) {
+ BT_ERR("Could not get adapter path\n");
+ return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
+ }
+
+ BT_INFO("Adapter path %s", adapter_path);
+
+ proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME, adapter_path,
+ BT_PROXIMITY_REPORTER_INTERFACE, NULL, NULL);
+
+ g_free(adapter_path);
+ retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ result = g_dbus_proxy_call_sync(proxy, "UnregisterProximity",
+ NULL, G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL, &error);
+ if (result == NULL) {
+ if (error != NULL) {
+ BT_ERR("Error occured in Proxy call [%s]\n", error->message);
+ g_error_free(error);
+ }
+ g_object_unref(proxy);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+ g_object_unref(proxy);
+
+ return BLUETOOTH_ERROR_NONE;
+}
#define BT_OBEXD_TRANSFER_INTERFACE "org.openobex.Transfer"
#define BT_A2DP_SOURCE_INTERFACE "org.bluez.AudioSource"
#define BT_PROXIMITY_MONITOR_INTERFACE "org.bluez.ProximityMonitor1"
+#define BT_PROXIMITY_REPORTER_INTERFACE "org.bluez.ProximityReporter1"
#define BT_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
BT_PXP_PROPERTY_TX_POWER = 0x04
} bt_proximity_alert_property_t;
+typedef enum {
+ BT_PXP_REPORTER_ROLE = 0x00,
+ BT_PXP_MONITOR_ROLE = 0x01,
+} bt_proximity_role_t;
+
int bt_set_proximity_property(bluetooth_device_address_t *device_address,
unsigned int property, int value);
int bt_get_proximity_supported_services(bluetooth_device_address_t *device_address,
unsigned int *supported_services);
+int bt_register_proximity_reporter();
+
+int bt_unregister_proximity_reporter();
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
BLUETOOTH_EVENT_IPSP_DISCONNECTED, /**< IPSP Disconnected event */
BLUETOOTH_EVENT_IPSP_INTERFACE_INFO, /** IPSP BT Interface Info after connection */
BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED, /** LE data length values changed */
+ BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED, /** Proximity property changed */
} bluetooth_event_type_t;
/**
guint16 max_rx_time;
} bt_le_data_length_params_t;
+/**
+ * Structure for proximity property change params
+ */
+typedef struct {
+ bluetooth_device_address_t device_address;
+ int role;
+ int service_type;
+ int alert_lvl;
+} bt_pxp_property_changed_params_t;
/**
* @brief DPM BT allowance state
*/
int bluetooth_get_proximity_supported_services(const bluetooth_device_address_t *device_address,
int *services_supported);
+
+/**
+ * @fn int bluetooth_register__proximity_reporter();
+ *
+ * @brief Register all proximity related services in BlueZ.
+ *
+ * This function is a synchronous call.
+ *
+ * @return BLUETOOTH_ERROR_NONE - Success \n
+ * BLUETOOTH_ERROR_NOT_FOUND - Cannot find the proxy\n
+ *
+ * @exception None
+ *
+ * @remark None
+ */
+int bluetooth_register_proximity_reporter();
+
+/**
+ * @fn int bluetooth_unregister__proximity_reporter();
+ *
+ * @brief Unregister all proximity related services in BlueZ.
+ *
+ * This function is a synchronous call.
+ *
+ * @return BLUETOOTH_ERROR_NONE - Success \n
+ * BLUETOOTH_ERROR_NOT_FOUND - Cannot find the proxy\n
+ *
+ * @exception None
+ *
+ * @remark None
+ */
+int bluetooth_unregister_proximity_reporter();
+
/**
* @}
*/
BT_PXP_SET_PROPERTY = BT_FUNC_PXP_BASE,
BT_PXP_GET_PROPERTY,
BT_PXP_GET_SUPPORTED_SERIVCES,
+ BT_PXP_REGISTER_REPORTER,
+ BT_PXP_UNREGISTER_REPORTER,
} bt_function_t;
typedef struct {
#define BT_IPSP_DISCONNECTED "IpspDisconnected"
#define BT_LE_DATA_LENGTH_CHANGED "LEDataLengthChanged"
#define BT_IBEACON_DEVICE_FOUND "iBeaconDeviceFound"
+#define BT_PXP_PROPERTY_CHANGED "PxpValueChanged"
#ifdef __cplusplus
}