iBeacon: Add support for handling iBeacon reports. 27/90927/8
authorh.sandeep <h.sandeep@samsung.com>
Wed, 5 Oct 2016 04:17:18 +0000 (09:47 +0530)
committerPyun DoHyun <dh79.pyun@samsung.com>
Wed, 2 Nov 2016 02:27:13 +0000 (19:27 -0700)
Change-Id: Ib0658eb8e610da76a588bb7f2cb21d580759626a
Signed-off-by: h.sandeep <h.sandeep@samsung.com>
bt-api/bt-event-handler.c
bt-service/bt-service-adapter-le.c
bt-service/bt-service-event-receiver.c
bt-service/bt-service-event-sender.c
bt-service/include/bt-service-adapter-le.h
bt-service/include/bt-service-common.h
include/bluetooth-api.h
include/bt-internal-types.h

index 7c3c09b..14ba549 100644 (file)
@@ -370,6 +370,43 @@ done:
        return le_dev_info;
 }
 
+static bluetooth_ibeacon_device_info_t *__bt_get_ibeacon_device_info_in_message(GVariant *parameters, int *ret)
+{
+       bluetooth_ibeacon_device_info_t *ibeacon_dev_info = NULL;
+       const char *address = NULL;
+       short addr_type = 0;
+       int company_id = 0;
+       int ibeacon_type = 0;
+       int major_id = 0;
+       int minor_id = 0;
+       int measured_power = 0;
+       const char *uuid = NULL;
+       int result = BLUETOOTH_ERROR_NONE;
+
+       g_variant_get(parameters, "(i&snnn&snnn)", &result, &address,
+                       &addr_type, &company_id, &ibeacon_type, &uuid, &major_id, &minor_id, &measured_power);
+       ibeacon_dev_info = g_malloc0(sizeof(bluetooth_ibeacon_device_info_t));
+       if (ibeacon_dev_info == NULL) {
+               result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
+               goto done;
+       }
+
+       _bt_convert_addr_string_to_type(ibeacon_dev_info->device_address.addr, address);
+       ibeacon_dev_info->addr_type = addr_type;
+       ibeacon_dev_info->company_id = company_id;
+       ibeacon_dev_info->ibeacon_type = ibeacon_type;
+       ibeacon_dev_info->major_id = major_id;
+       ibeacon_dev_info->minor_id = minor_id;
+       ibeacon_dev_info->measured_power = measured_power;
+       ibeacon_dev_info->uuid_len = strlen(uuid);
+       memcpy(ibeacon_dev_info->uuid, uuid, ibeacon_dev_info->uuid_len);
+done:
+
+       *ret = result;
+
+       return ibeacon_dev_info;
+}
+
 gboolean __bt_reliable_disable_cb(gpointer user_data)
 {
        BT_DBG("+");
@@ -747,6 +784,18 @@ void __bt_adapter_le_event_filter(GDBusConnection *connection,
                }
 
                g_free(le_device_info);
+       } else if (strcasecmp(signal_name, BT_IBEACON_DEVICE_FOUND) == 0) {
+               bluetooth_ibeacon_device_info_t *ibeacon_device_info;
+               BT_DBG("BT_IBEACON_DEVICE_FOUND");
+               ibeacon_device_info = __bt_get_ibeacon_device_info_in_message(parameters,
+                                                               &result);
+               ret_if(ibeacon_device_info == NULL);
+
+               _bt_common_event_cb(BLUETOOTH_EVENT_REMOTE_IBEACON_DEVICE_FOUND,
+                               result, ibeacon_device_info,
+                               event_info->cb, event_info->user_data);
+
+               g_free(ibeacon_device_info);
        }
 }
 
index eddbd36..fb4ac2c 100644 (file)
@@ -1946,6 +1946,36 @@ void _bt_send_scan_result_event(const bt_remote_le_dev_info_t *le_dev_info,
        }
 }
 
+void _bt_send_ibeacon_scan_result_event(const bt_remote_ibeacon_dev_info_t *ibeacon_dev_info)
+{
+       int result = BLUETOOTH_ERROR_NONE;
+       GSList *l;
+       GVariant *param;
+       bt_adapter_le_scanner_t *scanner = NULL;
+
+       ret_if(ibeacon_dev_info == NULL);
+       BT_DBG("_bt_send_ibeacon_scan_result_event");
+
+       for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
+               scanner = l->data;
+               if (scanner->is_scanning == FALSE)
+                       continue;
+
+               param = g_variant_new("(isnnnsnnn)",
+                                       result,
+                                       ibeacon_dev_info->address,
+                                       ibeacon_dev_info->addr_type,
+                                       ibeacon_dev_info->company_id,
+                                       ibeacon_dev_info->ibeacon_type,
+                                       ibeacon_dev_info->uuid,
+                                       ibeacon_dev_info->major_id,
+                                       ibeacon_dev_info->minor_id,
+                                       ibeacon_dev_info->measured_power);
+
+               _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_REMOTE_IBEACON_DEVICE_FOUND, param);
+       }
+}
+
 int _bt_add_white_list(bluetooth_device_address_t *device_address, bluetooth_device_address_type_t address_type)
 {
        GDBusProxy *proxy;
index 7aaf9c5..3610110 100644 (file)
@@ -2173,8 +2173,26 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                                                event,
                                                param);
                g_free(address);
-       }
+       } else if (strcasecmp(member, "iBeaconReport") == 0) {
+               bt_remote_ibeacon_dev_info_t *ibeacon_dev_info = NULL;
+
+               ret_if(_bt_is_le_scanning() == FALSE);
 
+               ibeacon_dev_info = g_malloc0(sizeof(bt_remote_ibeacon_dev_info_t));
+               if (ibeacon_dev_info == NULL)
+                       return;
+
+               g_variant_get(msg, "(syuusuuy)", &ibeacon_dev_info->address,
+                                               &ibeacon_dev_info->addr_type,
+                                               &ibeacon_dev_info->company_id,
+                                               &ibeacon_dev_info->ibeacon_type,
+                                               &ibeacon_dev_info->uuid,
+                                               &ibeacon_dev_info->major_id,
+                                               &ibeacon_dev_info->minor_id,
+                                               &ibeacon_dev_info->measured_power);
+               _bt_send_ibeacon_scan_result_event(ibeacon_dev_info);
+               g_free(ibeacon_dev_info);
+       }
 }
 
 void __bt_set_audio_values(gboolean connected, char *address)
index 5028fa0..0a8f1ef 100644 (file)
@@ -421,6 +421,9 @@ int _bt_send_event(int event_type, int event, GVariant *param)
        case BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED:
                signal = BT_LE_DATA_LENGTH_CHANGED;
                break;
+       case BLUETOOTH_EVENT_REMOTE_IBEACON_DEVICE_FOUND:
+               signal = BT_IBEACON_DEVICE_FOUND;
+               break;
        default:
                BT_ERR("Unknown event");
                return BLUETOOTH_ERROR_INTERNAL;
index 124a270..6c79a6e 100644 (file)
@@ -115,6 +115,8 @@ bt_le_scan_type_t _bt_get_le_scan_type(void);
 
 void _bt_send_scan_result_event(const bt_remote_le_dev_info_t *le_dev_info, const bt_le_adv_info_t *adv_info);
 
+void _bt_send_ibeacon_scan_result_event(const bt_remote_ibeacon_dev_info_t *ibeacon_dev_info);
+
 int _bt_add_white_list(bluetooth_device_address_t *device_address, bluetooth_device_address_type_t address_type);
 
 int _bt_remove_white_list(bluetooth_device_address_t *device_address, bluetooth_device_address_type_t address_type);
index fb73c79..d774b13 100644 (file)
@@ -303,6 +303,19 @@ typedef struct {
 } bt_remote_le_dev_info_t;
 
 typedef struct {
+       char *address;
+       int addr_type;
+       int rssi;
+       int adv_type;
+       int company_id;
+       int ibeacon_type;
+       int major_id;
+       int minor_id;
+       int measured_power;
+       char *uuid;
+} bt_remote_ibeacon_dev_info_t;
+
+typedef struct {
        int rssi;
        int class;
        char *address;
index 84ff2d9..fd99aa5 100644 (file)
@@ -521,6 +521,7 @@ typedef enum {
        BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,           /**< Bluetooth event LE discovery started */
        BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED,  /**< Bluetooth event LE discovery finished */
        BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND,     /**< Bluetooth event remote deice found (LE dev) */
+       BLUETOOTH_EVENT_REMOTE_IBEACON_DEVICE_FOUND,    /**< Bluetooth event remote ibeacon device found (iBeacon LE dev) */
        BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED,/**< Bluetooth event remote device name updated*/
        BLUETOOTH_EVENT_BONDING_FINISHED,           /**< Bluetooth event bonding completed */
        BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,      /**< Bluetooth event bonding removed */
@@ -999,6 +1000,20 @@ typedef struct {
 } bluetooth_le_device_info_t;
 
 typedef struct {
+       bluetooth_device_address_t device_address;      /**< device address */
+       int addr_type;                  /**< address type*/
+       int rssi;                       /**< received strength signal*/
+       int adv_type;
+       int company_id;         /** <Company ID> */
+       int ibeacon_type;       /** <iBeacon type> */
+       int major_id;           /** <Major ID> */
+       int minor_id;           /** <Minor ID> */
+       int measured_power; /** <Measured Power value for proximity> */
+       int uuid_len;           /** <uuid string len> */
+       char uuid[BLUETOOTH_UUID_STRING_MAX];   /** <customr/specific UUID> */
+} bluetooth_ibeacon_device_info_t;
+
+typedef struct {
        int slot_id;
        bluetooth_le_scan_filter_feature_t added_features;              /**< added features */
        bluetooth_device_address_t device_address;                      /**< device address */
index 5687b6f..e9532d3 100644 (file)
@@ -515,6 +515,7 @@ typedef struct {
 #define BT_IPSP_CONNECTED "IpspConnected"
 #define BT_IPSP_DISCONNECTED "IpspDisconnected"
 #define BT_LE_DATA_LENGTH_CHANGED "LEDataLengthChanged"
+#define BT_IBEACON_DEVICE_FOUND "iBeaconDeviceFound"
 
 #ifdef __cplusplus
 }