|
From: Alain P. <apa...@us...> - 2002-04-22 15:22:05
|
The following files were modified in apps/bluetooth/experimental:
Name Old version New version Tag Comment
---- ----------- ----------- --- -------
README.txt 1.5 1.6=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
bt_if.c 1.45 1.46=20=20=20=20=20=20=20=20=20=20=20=20=20=20
bt_if.h 1.33 1.34=20=20=20=20=20=20=20=20=20=20=20=20=20=20
btinq.c 1.3 1.4=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
bttest.c 1.26 1.27=20=20=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
Add an option to btinq to get the names of the remote devices.
The same option produce a formated output which contain BD addresses
and names.
The diff of the modified file(s):
--- README.txt 22 Apr 2002 14:29:22 -0000 1.5
+++ README.txt 22 Apr 2002 15:22:03 -0000 1.6
@@ -121,9 +121,25 @@
btinq.c
-------
Perform inquiry scan
-Syntax : btinq -n <max # returned> -t <max inq time>=20
+Syntax : btinq -n <max # returned> -t <max inq time> [-r]
e.g btinq -n 20 -t 15
=20
+If you want to get the names of the found remote devices and have a
+standard formated output, use option "-r" (for remote name).
+
+If you use option -r, you will recieve next format on standard ouput :
+
+<n>
+<name 1>
+<BT address 1>
+<name 2>
+<BT address 2>
+...
+
+where <n> will be the number of devices found
+ <name x> will be the name of the remote device x
+ <BT address x> will be the bluetooth hardware address of the
+ remote device x.
=20
By using these small apps together with btinit it will be possible to=20
do whole test 'suites' using e.g expect scripts or similar.
--- bt_if.c 8 Apr 2002 11:20:31 -0000 1.45
+++ bt_if.c 22 Apr 2002 15:22:03 -0000 1.46
@@ -973,7 +973,7 @@
=20
=20
int
-bt_inquiry(int bt_cfd, int nbr_rsp, int t)
+bt_inquiry(int bt_cfd, int nbr_rsp, int t, int get_name)
{
int retval =3D 0;
#ifdef BTD_USERSTACK
@@ -1001,11 +1001,60 @@
=20
if ((retval =3D ioctl(bt_cfd, HCIINQUIRY, inq_res)) < 0)
{
- printf("Inquiry failed [%s (%d)]\n", error_msg(retval), MSG_GET_CODE(-=
retval));
+ fprintf(stderr, "Inquiry failed [%s (%d)]\n", error_msg(retval), MSG_G=
ET_CODE(-retval));
free(inq_res);
return retval;
}
=20
+if (get_name)
+ {
+ unsigned char name_device[255];
+ /* First print the number of units found */
+ printf("%d", inq_res->nbr_of_units);
+=09
+ for (i =3D 0; i < inq_res->nbr_of_units; i++) {
+ /* Copy BD_ADDR to send in ioctl */
+ memcpy(name_device,inq_res->bd_addr + 6*i, 6);
+=20=20=20=20
+ if ((retval =3D ioctl(bt_cfd, HCIREMOTENAME_REQUEST, name_device)) < 0=
) {
+ fprintf (stderr, "Remote name request failed [%s (%d)]\n", error_msg=
(retval), MSG_GET_CODE(-retval));
+ /* Test if the problem is that the IOCTL doesn't exist */
+ if (errno =3D=3D EINVAL)
+ fprintf(stderr, "btinq : error : the ioctl HCIREMOTENAME_REQ=
UEST doesn't exist in the driver");
+ /* Print a default name */
+ printf("\nDevice with unknown name");
+ }
+ else {
+ switch (retval)
+ {
+ case 0x04: /* Page timeout */
+ printf("\nDevice with unknown name");
+ break;
+ case 0x00:
+ if (name_device[0] =3D=3D '\0') {
+ printf("Device with empty name\n");
+ }
+ else {
+ printf("\n%s", name_device);
+ }
+ break;
+ default:
+ printf("\nDevice with unrecoverable name");;
+ } /* Switch */
+
+ }
+
+ /* Print BD address */
+ printf("\n%02x:%02x:%02x:%02x:%02x:%02x",
+ inq_res->bd_addr[0+6*i], inq_res->bd_addr[1+6*i],
+ inq_res->bd_addr[2+6*i], inq_res->bd_addr[3+6*i],
+ inq_res->bd_addr[4+6*i], inq_res->bd_addr[5+6*i]);
+=09=20=20
+ } /* End of loop on every addresses founded */
+ } /* End of if get_name */
+else
+ {
+ /* Just write addresses as it was historically done */
for (i =3D 0; i < inq_res->nbr_of_units; i++)
{
printf("BD %d: %02x:%02x:%02x:%02x:%02x:%02x\n",i,
@@ -1014,6 +1063,7 @@
inq_res->bd_addr[4+6*i], inq_res->bd_addr[5+6*i]);
}
=20
+ }
free(inq_res);
#endif
return retval;
--- bt_if.h 8 Apr 2002 11:23:11 -0000 1.33
+++ bt_if.h 22 Apr 2002 15:22:03 -0000 1.34
@@ -349,7 +349,7 @@
int bt_getinfo(int bt_cfd, unsigned char bd[6], unsigned short type);
int bt_testcmd(int bt_cfd, unsigned char *cmd);
=20
-int bt_inquiry(int bt_cfd, int nbr_rsp, int t);
+int bt_inquiry(int bt_cfd, int nbr_rsp, int t, int get_name);
int bt_set_baudrate(int bt_cfd, const char *speedstr);
void bt_set_bd_addr(int bt_cfd, unsigned char *bd);
void read_local_bd(int bt_cfd, unsigned char *bd_addr);
--- btinq.c 14 May 2001 11:29:36 -0000 1.3
+++ btinq.c 22 Apr 2002 15:22:03 -0000 1.4
@@ -62,15 +62,16 @@
#include "bt_conf.h"
=20
/*=20
- * Syntax: btinq -n <max # returned> -t <max inq time>=20
+ * Syntax: btinq -n <max # returned> -t <max inq time> [-r]
*/
=20
int
main(int argc, char **argv)
{=20
int bt_cfd, opt, t =3D 10, nbr =3D 10;
+ int get_name =3D 0;
=20
- while ((opt =3D getopt(argc, argv, "n:t:")) !=3D -1)
+ while ((opt =3D getopt(argc, argv, "n:t:r")) !=3D -1)
{
switch(opt)
{
@@ -82,6 +83,11 @@
t =3D atoi(optarg);
break;
=20
+ case 'r':
+ /* Get the name of remote found devices */
+ get_name =3D 1;
+ break;
+=09=09=20
default:
break;
}
@@ -97,11 +103,11 @@
/* First of all check that stack is running */
if (!bt_isinitiated(bt_cfd))
{
- printf("Stack not initiated, exit\n");
+ fprintf(stderr, "Stack not initiated, exit\n");
exit(1);
}
=20
- bt_inquiry(bt_cfd, nbr, t);
+ bt_inquiry(bt_cfd, nbr, t, get_name);
=20=20
close(bt_cfd);
exit(0);
--- bttest.c 8 Apr 2002 11:22:08 -0000 1.26
+++ bttest.c 22 Apr 2002 15:22:03 -0000 1.27
@@ -486,7 +486,7 @@
}
else if (sscanf(buf, "inq %d %d", &tmp[0], &tmp[1]) =3D=3D 2)
{
- retval =3D bt_inquiry(bt_cfd, tmp[0], tmp[1]);
+ retval =3D bt_inquiry(bt_cfd, tmp[0], tmp[1], 0);
}
else if (sscanf(buf, "rf_send %d %d %d", &i, &repeat, &line) =3D=3D 3)
{
|