emulator: Add support to config the accept and resolve list
authorTedd Ho-Jeong An <tedd.an@intel.com>
Mon, 25 Oct 2021 20:31:17 +0000 (13:31 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:37 +0000 (19:08 +0530)
This patch adds interfaces to config the accept list and resolve list in
the btdev.

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 177633b9c17eb8b154c9e78fc5b835d978b79c6f..2cbe24edc20c38486fd7e481f682fc48e4e9617a 100755 (executable)
@@ -198,6 +198,10 @@ struct btdev {
        } __attribute__ ((packed)) le_cig;
        uint8_t  le_iso_path[2];
 
+       /* Real time length of AL array */
+       uint8_t le_al_len;
+       /* Real time length of RL array */
+       uint8_t le_rl_len;
        struct btdev_al le_al[AL_SIZE];
        struct btdev_rl le_rl[RL_SIZE];
        uint8_t  le_rl_enable;
@@ -482,6 +486,18 @@ static void rl_clear(struct btdev *dev)
                rl_reset(&dev->le_rl[i]);
 }
 
+/* Set the real time length of AL array */
+void btdev_set_al_len(struct btdev *btdev, uint8_t len)
+{
+       btdev->le_al_len = len;
+}
+
+/* Set the real time length of RL array */
+void btdev_set_rl_len(struct btdev *btdev, uint8_t len)
+{
+       btdev->le_rl_len = len;
+}
+
 static void btdev_reset(struct btdev *btdev)
 {
        /* FIXME: include here clearing of all states that should be
@@ -493,6 +509,9 @@ static void btdev_reset(struct btdev *btdev)
 
        al_clear(btdev);
        rl_clear(btdev);
+
+       btdev->le_al_len = AL_SIZE;
+       btdev->le_rl_len = RL_SIZE;
 }
 
 static int cmd_reset(struct btdev *dev, const void *data, uint8_t len)
@@ -3578,7 +3597,7 @@ static int cmd_read_al_size(struct btdev *dev, const void *data, uint8_t len)
        struct bt_hci_rsp_le_read_accept_list_size rsp;
 
        rsp.status = BT_HCI_ERR_SUCCESS;
-       rsp.size = AL_SIZE;
+       rsp.size = dev->le_al_len;
        cmd_complete(dev, BT_HCI_CMD_LE_READ_ACCEPT_LIST_SIZE, &rsp,
                                                sizeof(rsp));
 
@@ -3669,7 +3688,7 @@ static int cmd_add_al(struct btdev *dev, const void *data, uint8_t len)
                goto done;
        }
 
-       for (i = 0; i < AL_SIZE; i++) {
+       for (i = 0; i < dev->le_al_len; i++) {
                struct btdev_al *al = &dev->le_al[i];
 
                if (AL_ADDR_EQUAL(al, cmd->addr_type, &cmd->addr)) {
@@ -3731,7 +3750,7 @@ static int cmd_remove_al(struct btdev *dev, const void *data, uint8_t len)
                goto done;
        }
 
-       for (i = 0; i < AL_SIZE; i++) {
+       for (i = 0; i < dev->le_al_len; i++) {
                struct btdev_al *al = &dev->le_al[i];
 
                ba2str(&al->addr, addr);
@@ -3746,7 +3765,7 @@ static int cmd_remove_al(struct btdev *dev, const void *data, uint8_t len)
                }
        }
 
-       if (i == AL_SIZE) {
+       if (i == dev->le_al_len) {
                status = BT_HCI_ERR_INVALID_PARAMETERS;
                goto done;
        }
@@ -3785,7 +3804,7 @@ static int cmd_add_rl(struct btdev *dev, const void *data, uint8_t len)
                goto done;
        }
 
-       for (i = 0; i < RL_SIZE; i++) {
+       for (i = 0; i < dev->le_rl_len; i++) {
                struct btdev_rl *rl = &dev->le_rl[i];
 
                if (RL_ADDR_EQUAL(rl, cmd->addr_type, &cmd->addr)) {
@@ -3847,7 +3866,7 @@ static int cmd_remove_rl(struct btdev *dev, const void *data, uint8_t len)
                goto done;
        }
 
-       for (i = 0; i < RL_SIZE; i++) {
+       for (i = 0; i < dev->le_rl_len; i++) {
                struct btdev_rl *rl = &dev->le_rl[i];
 
                if (RL_ADDR_EQUAL(rl, cmd->addr_type, &cmd->addr)) {
@@ -3856,7 +3875,7 @@ static int cmd_remove_rl(struct btdev *dev, const void *data, uint8_t len)
                }
        }
 
-       if (i == RL_SIZE) {
+       if (i == dev->le_rl_len) {
                status = BT_HCI_ERR_INVALID_PARAMETERS;
                goto done;
        }
@@ -3902,7 +3921,7 @@ static int cmd_read_rl_size(struct btdev *dev, const void *data, uint8_t len)
        struct bt_hci_rsp_le_read_resolv_list_size rsp;
 
        rsp.status = BT_HCI_ERR_SUCCESS;
-       rsp.size = RL_SIZE;
+       rsp.size = dev->le_rl_len;
 
        cmd_complete(dev, BT_HCI_CMD_LE_READ_RESOLV_LIST_SIZE,
                                                        &rsp, sizeof(rsp));
@@ -6358,6 +6377,8 @@ struct btdev *btdev_create(enum btdev_type type, uint16_t id)
        btdev->conns = queue_new();
        btdev->le_ext_adv = queue_new();
 
+       btdev->le_al_len = AL_SIZE;
+       btdev->le_rl_len = RL_SIZE;
        return btdev;
 }
 
index 412bfd15811fe48f952d856680180185c5b8d3e8..b5f9979a82c3e2f1f6aaca5b6ee74e3ec5fa1054 100755 (executable)
@@ -80,6 +80,10 @@ uint8_t btdev_get_le_scan_enable(struct btdev *btdev);
 
 void btdev_set_le_states(struct btdev *btdev, const uint8_t *le_states);
 
+void btdev_set_al_len(struct btdev *btdev, uint8_t len);
+
+void btdev_set_rl_len(struct btdev *btdev, uint8_t len);
+
 void btdev_set_command_handler(struct btdev *btdev, btdev_command_func handler,
                                                        void *user_data);
 
index ebbb427b6ee22df69d6b60f664f8d18c7b7ee8f2..1109c087c9a0287b21ea95fe29067f5532ff5a6d 100755 (executable)
@@ -600,6 +600,34 @@ void hciemu_set_central_le_states(struct hciemu *hciemu,
        btdev_set_le_states(dev, le_states);
 }
 
+void hciemu_set_central_le_al_len(struct hciemu *hciemu, uint8_t len)
+{
+       struct btdev *dev;
+
+       if (!hciemu || !hciemu->vhci)
+               return;
+
+       dev = vhci_get_btdev(hciemu->vhci);
+       if (!dev)
+               return;
+
+       btdev_set_al_len(dev, len);
+}
+
+void hciemu_set_central_le_rl_len(struct hciemu *hciemu, uint8_t len)
+{
+       struct btdev *dev;
+
+       if (!hciemu || !hciemu->vhci)
+               return;
+
+       dev = vhci_get_btdev(hciemu->vhci);
+       if (!dev)
+               return;
+
+       btdev_set_rl_len(dev, len);
+}
+
 bool hciemu_add_central_post_command_hook(struct hciemu *hciemu,
                        hciemu_command_func_t function, void *user_data)
 {
index 338fa844d67328f1674a8ae2f38d157f4f1f6b85..2a49d8bad83e202dc29a9e4dd631ceed40ba1daa 100755 (executable)
@@ -61,6 +61,10 @@ uint8_t hciemu_get_central_le_scan_enable(struct hciemu *hciemu);
 void hciemu_set_central_le_states(struct hciemu *hciemu,
                                                const uint8_t *le_states);
 
+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);
+
 typedef void (*hciemu_command_func_t)(uint16_t opcode, const void *data,
                                                uint8_t len, void *user_data);