diff --git a/emulator/main.c b/emulator/main.c
index 7edc57c..82f7212 100644
--- a/emulator/main.c
+++ b/emulator/main.c
int main(int argc, char *argv[])
{
struct vhci *vhci;
- struct server *server;
+ struct server *server1;
+ struct server *server2;
sigset_t mask;
mainloop_init();
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 f2455e9..7d780bb 100644
--- a/emulator/server.c
+++ b/emulator/server.c
#include "btdev.h"
#include "server.h"
+#define uninitialized_var(x) x = x
+
struct server {
+ enum server_type type;
uint16_t id;
int fd;
};
{
struct server *server = user_data;
struct client *client;
+ enum btdev_type uninitialized_var(type);
if (events & (EPOLLERR | EPOLLHUP))
return;
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);
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;
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) {
return fd;
}
-struct server *server_open_tcp(uint16_t id)
+struct server *server_open_tcp(enum server_type type)
{
struct server *server;
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 f2b95a2..412ea68 100644
--- a/emulator/server.h
+++ b/emulator/server.h
#include <stdint.h>
+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 913ae81..6b66105 100644
--- a/emulator/vhci.c
+++ b/emulator/vhci.c
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;
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 4abb183..a9d8069 100644
--- a/emulator/vhci.h
+++ b/emulator/vhci.h
#include <stdint.h>
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);