mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-11-17 01:04:40 +08:00
emulator: Create support for enabling AMP controllers
This commit is contained in:
parent
2c33d253f5
commit
9f3814a34f
@ -45,7 +45,8 @@ static void signal_callback(int signum, void *user_data)
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct vhci *vhci;
|
struct vhci *vhci;
|
||||||
struct server *server;
|
struct server *server1;
|
||||||
|
struct server *server2;
|
||||||
sigset_t mask;
|
sigset_t mask;
|
||||||
|
|
||||||
mainloop_init();
|
mainloop_init();
|
||||||
@ -56,13 +57,17 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
mainloop_set_signal(&mask, signal_callback, NULL, NULL);
|
mainloop_set_signal(&mask, signal_callback, NULL, NULL);
|
||||||
|
|
||||||
vhci = vhci_open(VHCI_TYPE_BREDR, 0x23);
|
vhci = vhci_open(VHCI_TYPE_BREDR);
|
||||||
if (!vhci)
|
if (!vhci)
|
||||||
fprintf(stderr, "Failed to open Virtual HCI device\n");
|
fprintf(stderr, "Failed to open Virtual HCI device\n");
|
||||||
|
|
||||||
server = server_open_unix("/tmp/bt-server-bredr", 0x42);
|
server1 = server_open_unix(SERVER_TYPE_BREDR, "/tmp/bt-server-bredr");
|
||||||
if (!server)
|
if (!server1)
|
||||||
fprintf(stderr, "Failed to open server channel\n");
|
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();
|
return mainloop_run();
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,10 @@
|
|||||||
#include "btdev.h"
|
#include "btdev.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
|
#define uninitialized_var(x) x = x
|
||||||
|
|
||||||
struct server {
|
struct server {
|
||||||
|
enum server_type type;
|
||||||
uint16_t id;
|
uint16_t id;
|
||||||
int fd;
|
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 server *server = user_data;
|
||||||
struct client *client;
|
struct client *client;
|
||||||
|
enum btdev_type uninitialized_var(type);
|
||||||
|
|
||||||
if (events & (EPOLLERR | EPOLLHUP))
|
if (events & (EPOLLERR | EPOLLHUP))
|
||||||
return;
|
return;
|
||||||
@ -205,7 +209,16 @@ static void server_accept_callback(int fd, uint32_t events, void *user_data)
|
|||||||
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) {
|
if (!client->btdev) {
|
||||||
close(client->fd);
|
close(client->fd);
|
||||||
free(client);
|
free(client);
|
||||||
@ -254,7 +267,7 @@ static int open_unix(const char *path)
|
|||||||
return fd;
|
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;
|
struct server *server;
|
||||||
|
|
||||||
@ -263,7 +276,8 @@ struct server *server_open_unix(const char *path, uint16_t id)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
memset(server, 0, sizeof(*server));
|
memset(server, 0, sizeof(*server));
|
||||||
server->id = id;
|
server->type = type;
|
||||||
|
server->id = 0x42;
|
||||||
|
|
||||||
server->fd = open_unix(path);
|
server->fd = open_unix(path);
|
||||||
if (server->fd < 0) {
|
if (server->fd < 0) {
|
||||||
@ -315,7 +329,7 @@ static int open_tcp(void)
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct server *server_open_tcp(uint16_t id)
|
struct server *server_open_tcp(enum server_type type)
|
||||||
{
|
{
|
||||||
struct server *server;
|
struct server *server;
|
||||||
|
|
||||||
@ -324,7 +338,8 @@ struct server *server_open_tcp(uint16_t id)
|
|||||||
return server;
|
return server;
|
||||||
|
|
||||||
memset(server, 0, sizeof(*server));
|
memset(server, 0, sizeof(*server));
|
||||||
server->id = id;
|
server->type = type;
|
||||||
|
server->id = 0x43;
|
||||||
|
|
||||||
server->fd = open_tcp();
|
server->fd = open_tcp();
|
||||||
if (server->fd < 0) {
|
if (server->fd < 0) {
|
||||||
|
@ -24,8 +24,13 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
enum server_type {
|
||||||
|
SERVER_TYPE_BREDR,
|
||||||
|
SERVER_TYPE_AMP,
|
||||||
|
};
|
||||||
|
|
||||||
struct server;
|
struct server;
|
||||||
|
|
||||||
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_open_tcp(uint16_t id);
|
struct server *server_open_tcp(enum server_type type);
|
||||||
void server_close(struct server *server);
|
void server_close(struct server *server);
|
||||||
|
@ -80,7 +80,7 @@ static void vhci_read_callback(int fd, uint32_t events, void *user_data)
|
|||||||
btdev_receive_h4(vhci->btdev, buf, len);
|
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;
|
struct vhci *vhci;
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ struct vhci *vhci_open(enum vhci_type type, uint16_t id)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
vhci->btdev = btdev_create(BTDEV_TYPE_BREDR, id);
|
vhci->btdev = btdev_create(BTDEV_TYPE_BREDR, 0x23);
|
||||||
if (!vhci->btdev) {
|
if (!vhci->btdev) {
|
||||||
close(vhci->fd);
|
close(vhci->fd);
|
||||||
free(vhci);
|
free(vhci);
|
||||||
|
@ -25,11 +25,11 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
enum vhci_type {
|
enum vhci_type {
|
||||||
VHCI_TYPE_BREDR = 0,
|
VHCI_TYPE_BREDR,
|
||||||
VHCI_TYPE_AMP = 1,
|
VHCI_TYPE_AMP,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct vhci;
|
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);
|
void vhci_close(struct vhci *vhci);
|
||||||
|
Loading…
Reference in New Issue
Block a user