OSDN Git Service

emulator/bthost: Add support for creating LE connections
authorJohan Hedberg <johan.hedberg@intel.com>
Fri, 20 Sep 2013 15:16:19 +0000 (18:16 +0300)
committerJohan Hedberg <johan.hedberg@intel.com>
Wed, 25 Sep 2013 10:51:11 +0000 (13:51 +0300)
emulator/bthost.c
emulator/bthost.h
tools/l2cap-tester.c

index cdcde06..da56b5c 100644 (file)
@@ -1055,14 +1055,28 @@ void bthost_set_connect_cb(struct bthost *bthost, bthost_new_conn_cb cb,
        bthost->new_conn_data = user_data;
 }
 
-void bthost_hci_connect(struct bthost *bthost, const uint8_t *bdaddr)
+void bthost_hci_connect(struct bthost *bthost, const uint8_t *bdaddr,
+                                                       uint8_t addr_type)
 {
-       struct bt_hci_cmd_create_conn cmd;
+       if (addr_type == BDADDR_BREDR) {
+               struct bt_hci_cmd_create_conn cc;
 
-       memset(&cmd, 0, sizeof(cmd));
-       memcpy(cmd.bdaddr, bdaddr, sizeof(cmd.bdaddr));
+               memset(&cc, 0, sizeof(cc));
+               memcpy(cc.bdaddr, bdaddr, sizeof(cc.bdaddr));
+
+               send_command(bthost, BT_HCI_CMD_CREATE_CONN, &cc, sizeof(cc));
+       } else {
+               struct bt_hci_cmd_le_create_conn cc;
 
-       send_command(bthost, BT_HCI_CMD_CREATE_CONN, &cmd, sizeof(cmd));
+               memset(&cc, 0, sizeof(cc));
+               memcpy(cc.peer_addr, bdaddr, sizeof(cc.peer_addr));
+
+               if (addr_type == BDADDR_LE_RANDOM)
+                       cc.peer_addr_type = 0x01;
+
+               send_command(bthost, BT_HCI_CMD_LE_CREATE_CONN,
+                                                       &cc, sizeof(cc));
+       }
 }
 
 void bthost_write_scan_enable(struct bthost *bthost, uint8_t scan)
index dd497e8..cd5bf1c 100644 (file)
@@ -49,7 +49,8 @@ typedef void (*bthost_new_conn_cb) (uint16_t handle, void *user_data);
 void bthost_set_connect_cb(struct bthost *bthost, bthost_new_conn_cb cb,
                                                        void *user_data);
 
-void bthost_hci_connect(struct bthost *bthost, const uint8_t *bdaddr);
+void bthost_hci_connect(struct bthost *bthost, const uint8_t *bdaddr,
+                                                       uint8_t addr_type);
 
 typedef void (*bthost_l2cap_rsp_cb) (uint8_t code, const void *data,
                                                uint16_t len, void *user_data);
index 20b84be..6f267d2 100644 (file)
@@ -591,6 +591,7 @@ static void test_bredr_server(const void *test_data)
        struct test_data *data = tester_get_data();
        const struct l2cap_server_data *l2data = data->test_data;
        const uint8_t *master_bdaddr;
+       uint8_t addr_type;
        struct bthost *bthost;
        GIOChannel *io;
        int sk;
@@ -628,7 +629,13 @@ static void test_bredr_server(const void *test_data)
 
        bthost = hciemu_client_get_host(data->hciemu);
        bthost_set_connect_cb(bthost, client_new_conn, data);
-       bthost_hci_connect(bthost, master_bdaddr);
+
+       if (data->hciemu_type == HCIEMU_TYPE_BREDR)
+               addr_type = BDADDR_BREDR;
+       else
+               addr_type = BDADDR_LE_PUBLIC;
+
+       bthost_hci_connect(bthost, master_bdaddr, addr_type);
 }
 
 int main(int argc, char *argv[])