emulator/bthost: Add support for creating LE connections

This commit is contained in:
Johan Hedberg 2013-09-20 18:16:19 +03:00
parent f4bbedec71
commit 5d8b3ba494
3 changed files with 29 additions and 7 deletions

View 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, &cmd, sizeof(cmd));
send_command(bthost, BT_HCI_CMD_CREATE_CONN, &cc, sizeof(cc));
} else {
struct bt_hci_cmd_le_create_conn cc;
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)

View 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);

View 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[])