From 9f3814a34f0b3718104446906ee75202a1b84aed Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 29 Oct 2012 15:49:30 -0700 Subject: [PATCH] emulator: Create support for enabling AMP controllers --- emulator/main.c | 15 ++++++++++----- emulator/server.c | 25 ++++++++++++++++++++----- emulator/server.h | 9 +++++++-- emulator/vhci.c | 4 ++-- emulator/vhci.h | 6 +++--- 5 files changed, 42 insertions(+), 17 deletions(-) diff --git a/emulator/main.c b/emulator/main.c index 7edc57c01..82f7212d3 100644 --- a/emulator/main.c +++ b/emulator/main.c @@ -45,7 +45,8 @@ static void signal_callback(int signum, void *user_data) int main(int argc, char *argv[]) { struct vhci *vhci; - struct server *server; + struct server *server1; + struct server *server2; sigset_t mask; mainloop_init(); @@ -56,13 +57,17 @@ int main(int argc, char *argv[]) mainloop_set_signal(&mask, signal_callback, NULL, NULL); - vhci = vhci_open(VHCI_TYPE_BREDR, 0x23); + vhci = vhci_open(VHCI_TYPE_BREDR); if (!vhci) fprintf(stderr, "Failed to open Virtual HCI device\n"); - server = server_open_unix("/tmp/bt-server-bredr", 0x42); - if (!server) - fprintf(stderr, "Failed to open server channel\n"); + server1 = server_open_unix(SERVER_TYPE_BREDR, "/tmp/bt-server-bredr"); + if (!server1) + fprintf(stderr, "Failed to open BR/EDR server channel\n"); + + server2 = server_open_unix(SERVER_TYPE_BREDR, "/tmp/bt-server-amp"); + if (!server2) + fprintf(stderr, "Failed to open AMP server channel\n"); return mainloop_run(); } diff --git a/emulator/server.c b/emulator/server.c index f2455e9d8..7d780bb88 100644 --- a/emulator/server.c +++ b/emulator/server.c @@ -46,7 +46,10 @@ #include "btdev.h" #include "server.h" +#define uninitialized_var(x) x = x + struct server { + enum server_type type; uint16_t id; int fd; }; @@ -189,6 +192,7 @@ static void server_accept_callback(int fd, uint32_t events, void *user_data) { struct server *server = user_data; struct client *client; + enum btdev_type uninitialized_var(type); if (events & (EPOLLERR | EPOLLHUP)) return; @@ -205,7 +209,16 @@ static void server_accept_callback(int fd, uint32_t events, void *user_data) return; } - client->btdev = btdev_create(BTDEV_TYPE_BREDR, server->id); + switch (server->type) { + case SERVER_TYPE_BREDR: + type = BTDEV_TYPE_BREDR; + break; + case SERVER_TYPE_AMP: + type = BTDEV_TYPE_AMP; + break; + } + + client->btdev = btdev_create(type, server->id); if (!client->btdev) { close(client->fd); free(client); @@ -254,7 +267,7 @@ static int open_unix(const char *path) return fd; } -struct server *server_open_unix(const char *path, uint16_t id) +struct server *server_open_unix(enum server_type type, const char *path) { struct server *server; @@ -263,7 +276,8 @@ struct server *server_open_unix(const char *path, uint16_t id) return NULL; memset(server, 0, sizeof(*server)); - server->id = id; + server->type = type; + server->id = 0x42; server->fd = open_unix(path); if (server->fd < 0) { @@ -315,7 +329,7 @@ static int open_tcp(void) return fd; } -struct server *server_open_tcp(uint16_t id) +struct server *server_open_tcp(enum server_type type) { struct server *server; @@ -324,7 +338,8 @@ struct server *server_open_tcp(uint16_t id) return server; memset(server, 0, sizeof(*server)); - server->id = id; + server->type = type; + server->id = 0x43; server->fd = open_tcp(); if (server->fd < 0) { diff --git a/emulator/server.h b/emulator/server.h index f2b95a20f..412ea686a 100644 --- a/emulator/server.h +++ b/emulator/server.h @@ -24,8 +24,13 @@ #include +enum server_type { + SERVER_TYPE_BREDR, + SERVER_TYPE_AMP, +}; + struct server; -struct server *server_open_unix(const char *path, uint16_t id); -struct server *server_open_tcp(uint16_t id); +struct server *server_open_unix(enum server_type type, const char *path); +struct server *server_open_tcp(enum server_type type); void server_close(struct server *server); diff --git a/emulator/vhci.c b/emulator/vhci.c index 913ae8174..6b66105c5 100644 --- a/emulator/vhci.c +++ b/emulator/vhci.c @@ -80,7 +80,7 @@ static void vhci_read_callback(int fd, uint32_t events, void *user_data) btdev_receive_h4(vhci->btdev, buf, len); } -struct vhci *vhci_open(enum vhci_type type, uint16_t id) +struct vhci *vhci_open(enum vhci_type type) { struct vhci *vhci; @@ -104,7 +104,7 @@ struct vhci *vhci_open(enum vhci_type type, uint16_t id) return NULL; } - vhci->btdev = btdev_create(BTDEV_TYPE_BREDR, id); + vhci->btdev = btdev_create(BTDEV_TYPE_BREDR, 0x23); if (!vhci->btdev) { close(vhci->fd); free(vhci); diff --git a/emulator/vhci.h b/emulator/vhci.h index 4abb18303..a9d80692b 100644 --- a/emulator/vhci.h +++ b/emulator/vhci.h @@ -25,11 +25,11 @@ #include enum vhci_type { - VHCI_TYPE_BREDR = 0, - VHCI_TYPE_AMP = 1, + VHCI_TYPE_BREDR, + VHCI_TYPE_AMP, }; struct vhci; -struct vhci *vhci_open(enum vhci_type type, uint16_t id); +struct vhci *vhci_open(enum vhci_type type); void vhci_close(struct vhci *vhci); -- 2.47.3