emulator: Add support to get the advertising address
authorTedd Ho-Jeong An <tedd.an@intel.com>
Mon, 25 Oct 2021 20:31:19 +0000 (13:31 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:37 +0000 (19:08 +0530)
This patch add supprt emulator to get the advertising address of the
central device.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
emulator/btdev.c
emulator/btdev.h
emulator/hciemu.c
emulator/hciemu.h

index 2cbe24e..7b311f3 100755 (executable)
@@ -4703,6 +4703,7 @@ static void send_ext_adv(struct btdev *btdev, const struct btdev *remote,
                                        struct le_ext_adv *ext_adv,
                                        uint16_t type, bool is_scan_rsp)
 {
+
        struct __packed {
                uint8_t num_reports;
                union {
@@ -4818,6 +4819,9 @@ static int cmd_set_ext_adv_enable(struct btdev *dev, const void *data,
 
                /* Disable all advertising sets */
                queue_foreach(dev->le_ext_adv, ext_adv_disable, NULL);
+
+               dev->le_adv_enable = 0x00;
+
                goto exit_complete;
        }
 
@@ -4872,6 +4876,8 @@ static int cmd_set_ext_adv_enable(struct btdev *dev, const void *data,
 
                ext_adv->enable = cmd->enable;
 
+               dev->le_adv_enable = 0x01;
+
                if (!cmd->enable)
                        ext_adv_disable(ext_adv, NULL);
                else if (eas->duration)
@@ -4936,7 +4942,7 @@ static int cmd_remove_adv_set(struct btdev *dev, const void *data,
                                                UINT_TO_PTR(cmd->handle));
        if (!ext_adv) {
                status = BT_HCI_ERR_UNKNOWN_ADVERTISING_ID;
-               cmd_complete(dev, BT_HCI_CMD_LE_SET_EXT_ADV_DATA, &status,
+               cmd_complete(dev, BT_HCI_CMD_LE_REMOVE_ADV_SET, &status,
                                                sizeof(status));
                return 0;
        }
@@ -5206,7 +5212,7 @@ static void le_ext_conn_complete(struct btdev *btdev,
                /* Set Local RPA if an RPA was generated for the advertising */
                if (ext_adv->rpa)
                        memcpy(ev.local_rpa, ext_adv->random_addr,
-                                       sizeof(ev.local_rpa));
+                                                       sizeof(ev.local_rpa));
 
                le_meta_event(conn->link->dev,
                                BT_HCI_EVT_LE_ENHANCED_CONN_COMPLETE, &ev,
@@ -6435,6 +6441,19 @@ uint8_t btdev_get_le_scan_enable(struct btdev *btdev)
        return btdev->le_scan_enable;
 }
 
+const uint8_t *btdev_get_adv_addr(struct btdev *btdev, uint8_t handle)
+{
+       struct le_ext_adv *ext_adv;
+
+       /* Check if Ext Adv is already existed */
+       ext_adv = queue_find(btdev->le_ext_adv, match_ext_adv_handle,
+                                                       UINT_TO_PTR(handle));
+       if (!ext_adv)
+               return NULL;
+
+       return ext_adv_addr(btdev, ext_adv);
+}
+
 void btdev_set_le_states(struct btdev *btdev, const uint8_t *le_states)
 {
        memcpy(btdev->le_states, le_states, sizeof(btdev->le_states));
index b5f9979..9493938 100755 (executable)
@@ -78,6 +78,8 @@ uint8_t btdev_get_scan_enable(struct btdev *btdev);
 
 uint8_t btdev_get_le_scan_enable(struct btdev *btdev);
 
+const uint8_t *btdev_get_adv_addr(struct btdev *btdev, uint8_t handle);
+
 void btdev_set_le_states(struct btdev *btdev, const uint8_t *le_states);
 
 void btdev_set_al_len(struct btdev *btdev, uint8_t len);
index 1109c08..541409a 100755 (executable)
@@ -628,6 +628,21 @@ void hciemu_set_central_le_rl_len(struct hciemu *hciemu, uint8_t len)
        btdev_set_rl_len(dev, len);
 }
 
+const uint8_t *hciemu_get_central_adv_addr(struct hciemu *hciemu,
+                                                               uint8_t handle)
+{
+       struct btdev *dev;
+
+       if (!hciemu || !hciemu->vhci)
+               return NULL;
+
+       dev = vhci_get_btdev(hciemu->vhci);
+       if (!dev)
+               return NULL;
+
+       return btdev_get_adv_addr(dev, handle);
+}
+
 bool hciemu_add_central_post_command_hook(struct hciemu *hciemu,
                        hciemu_command_func_t function, void *user_data)
 {
index 2a49d8b..3a06ca5 100755 (executable)
@@ -65,6 +65,9 @@ void hciemu_set_central_le_al_len(struct hciemu *hciemu, uint8_t len);
 
 void hciemu_set_central_le_rl_len(struct hciemu *hciemu, uint8_t len);
 
+const uint8_t *hciemu_get_central_adv_addr(struct hciemu *hciemu,
+                                                       uint8_t handle);
+
 typedef void (*hciemu_command_func_t)(uint16_t opcode, const void *data,
                                                uint8_t len, void *user_data);