For testing multiple devices, it's nice to use a hciemu for each virtual
device. The problem is that their addresses are always the same.
This patch series removes the static address assignment made in
hciemu_new/create_vhci.
Inside btdev_create, it already generated a specific address, so we can
just reuse it.
Jefferson Delfes (3):
emulator: Add getter function for device address in btdev
shared: Remove static address assignment in hciemu
shared: Return real address of master dev in hciemu
emulator/btdev.c | 5 +++++
emulator/btdev.h | 1 +
src/shared/hciemu.c | 21 ++++++++++-----------
3 files changed, 16 insertions(+), 11 deletions(-)
--
1.8.2
Hi Lizardo,
On Thu, Apr 11, 2013, Anderson Lizardo wrote:
> On Thu, Apr 11, 2013 at 11:24 AM, Jefferson Delfes
> <[email protected]> wrote:
> > diff --git a/src/shared/hciemu.c b/src/shared/hciemu.c
> > index 60a4f47..8cd6548 100644
> > --- a/src/shared/hciemu.c
> > +++ b/src/shared/hciemu.c
> > @@ -192,20 +192,12 @@ static guint create_source_btdev(int fd, struct btdev *btdev)
> > static bool create_vhci(struct hciemu *hciemu)
> > {
> > struct btdev *btdev;
> > - uint8_t bdaddr[6];
> > - const char *str;
> > - int fd, i;
> > + int fd;
> >
> > btdev = btdev_create(hciemu->btdev_type, 0x00);
> > if (!btdev)
> > return false;
> >
> > - str = hciemu_get_address(hciemu);
> > -
> > - for (i = 5; i >= 0; i--, str += 3)
> > - bdaddr[i] = strtol(str, NULL, 16);
> > -
> > - btdev_set_bdaddr(btdev, bdaddr);
>
> Looks like you can remove btdev_set_bdaddr() (in a patch after this
> one) because it was the only user of this function.
Yep. I already went ahead and pushed such a patch upstream.
Johan
HI Jefferson,
On Thu, Apr 11, 2013, Jefferson Delfes wrote:
> For testing multiple devices, it's nice to use a hciemu for each virtual
> device. The problem is that their addresses are always the same.
>
> This patch series removes the static address assignment made in
> hciemu_new/create_vhci.
> Inside btdev_create, it already generated a specific address, so we can
> just reuse it.
>
> Jefferson Delfes (3):
> emulator: Add getter function for device address in btdev
> shared: Remove static address assignment in hciemu
> shared: Return real address of master dev in hciemu
>
> emulator/btdev.c | 5 +++++
> emulator/btdev.h | 1 +
> src/shared/hciemu.c | 21 ++++++++++-----------
> 3 files changed, 16 insertions(+), 11 deletions(-)
All three patches have been applied. Thanks.
Johan
Hi Jefferson,
On Thu, Apr 11, 2013 at 11:24 AM, Jefferson Delfes
<[email protected]> wrote:
> diff --git a/src/shared/hciemu.c b/src/shared/hciemu.c
> index 60a4f47..8cd6548 100644
> --- a/src/shared/hciemu.c
> +++ b/src/shared/hciemu.c
> @@ -192,20 +192,12 @@ static guint create_source_btdev(int fd, struct btdev *btdev)
> static bool create_vhci(struct hciemu *hciemu)
> {
> struct btdev *btdev;
> - uint8_t bdaddr[6];
> - const char *str;
> - int fd, i;
> + int fd;
>
> btdev = btdev_create(hciemu->btdev_type, 0x00);
> if (!btdev)
> return false;
>
> - str = hciemu_get_address(hciemu);
> -
> - for (i = 5; i >= 0; i--, str += 3)
> - bdaddr[i] = strtol(str, NULL, 16);
> -
> - btdev_set_bdaddr(btdev, bdaddr);
Looks like you can remove btdev_set_bdaddr() (in a patch after this
one) because it was the only user of this function.
Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
Exports master btdev address in hciemu.
---
src/shared/hciemu.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/shared/hciemu.c b/src/shared/hciemu.c
index 8cd6548..133f16f 100644
--- a/src/shared/hciemu.c
+++ b/src/shared/hciemu.c
@@ -25,6 +25,7 @@
#include <config.h>
#endif
+#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
@@ -49,6 +50,7 @@ struct hciemu {
guint master_source;
guint client_source;
GList *post_command_hooks;
+ char bdaddr_str[18];
};
struct hciemu_command_hook {
@@ -331,10 +333,15 @@ void hciemu_unref(struct hciemu *hciemu)
const char *hciemu_get_address(struct hciemu *hciemu)
{
- if (!hciemu)
+ const uint8_t *addr;
+
+ if (!hciemu || !hciemu->master_dev)
return NULL;
- return "00:FA:CE:1E:55:00";
+ addr = btdev_get_bdaddr(hciemu->master_dev);
+ sprintf(hciemu->bdaddr_str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
+ addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
+ return hciemu->bdaddr_str;
}
bool hciemu_add_master_post_command_hook(struct hciemu *hciemu,
--
1.8.2
If we need multiple virtual devices, addresses should not be the same.
Inside the function btdev_create, a specific address is generated.
---
src/shared/hciemu.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/src/shared/hciemu.c b/src/shared/hciemu.c
index 60a4f47..8cd6548 100644
--- a/src/shared/hciemu.c
+++ b/src/shared/hciemu.c
@@ -192,20 +192,12 @@ static guint create_source_btdev(int fd, struct btdev *btdev)
static bool create_vhci(struct hciemu *hciemu)
{
struct btdev *btdev;
- uint8_t bdaddr[6];
- const char *str;
- int fd, i;
+ int fd;
btdev = btdev_create(hciemu->btdev_type, 0x00);
if (!btdev)
return false;
- str = hciemu_get_address(hciemu);
-
- for (i = 5; i >= 0; i--, str += 3)
- bdaddr[i] = strtol(str, NULL, 16);
-
- btdev_set_bdaddr(btdev, bdaddr);
btdev_set_command_handler(btdev, master_command_callback, hciemu);
fd = open("/dev/vhci", O_RDWR | O_NONBLOCK | O_CLOEXEC);
--
1.8.2
This helper function returns bdaddr field from btdev.
---
emulator/btdev.c | 5 +++++
emulator/btdev.h | 1 +
2 files changed, 6 insertions(+)
diff --git a/emulator/btdev.c b/emulator/btdev.c
index b74442e..41d0e0e 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -319,6 +319,11 @@ void btdev_set_bdaddr(struct btdev *btdev, uint8_t *bdaddr)
memcpy(btdev->bdaddr, bdaddr, 6);
}
+const uint8_t *btdev_get_bdaddr(struct btdev *btdev)
+{
+ return btdev->bdaddr;
+}
+
void btdev_set_command_handler(struct btdev *btdev, btdev_command_func handler,
void *user_data)
{
diff --git a/emulator/btdev.h b/emulator/btdev.h
index ef71a9b..fb4df66 100644
--- a/emulator/btdev.h
+++ b/emulator/btdev.h
@@ -66,6 +66,7 @@ struct btdev *btdev_create(enum btdev_type type, uint16_t id);
void btdev_destroy(struct btdev *btdev);
void btdev_set_bdaddr(struct btdev *btdev, uint8_t *bdaddr);
+const uint8_t *btdev_get_bdaddr(struct btdev *btdev);
void btdev_set_command_handler(struct btdev *btdev, btdev_command_func handler,
void *user_data);
--
1.8.2