summaryrefslogtreecommitdiff
path: root/host
diff options
context:
space:
mode:
authorMike Ryan <mikeryan@lacklustre.net>2016-03-04 17:26:11 -0800
committerMike Ryan <mikeryan@lacklustre.net>2016-03-04 17:26:11 -0800
commit991998a6a5b9a073db521959658de8ec40943109 (patch)
treee92198ffd15de1cdbc81d6cfcf4e78e2a120c3b9 /host
parentce442ee24d712a4f04ce337a28291428ffb01664 (diff)
long-needed API version in firmware and host tools
The firmware now reports its current API version, and most of the host tools validate that the firmware is using the expected API.
Diffstat (limited to 'host')
-rw-r--r--host/libubertooth/src/ubertooth.c21
-rw-r--r--host/libubertooth/src/ubertooth.h1
-rw-r--r--host/libubertooth/src/ubertooth_control.c13
-rw-r--r--host/libubertooth/src/ubertooth_control.h1
-rw-r--r--host/libubertooth/src/ubertooth_interface.h4
-rw-r--r--host/ubertooth-tools/src/ubertooth-afh.c5
-rw-r--r--host/ubertooth-tools/src/ubertooth-btle.c4
-rw-r--r--host/ubertooth-tools/src/ubertooth-dump.c5
-rw-r--r--host/ubertooth-tools/src/ubertooth-ego.c4
-rw-r--r--host/ubertooth-tools/src/ubertooth-follow.c5
-rw-r--r--host/ubertooth-tools/src/ubertooth-rx.c4
-rw-r--r--host/ubertooth-tools/src/ubertooth-scan.c4
-rw-r--r--host/ubertooth-tools/src/ubertooth-specan.c4
-rw-r--r--host/ubertooth-tools/src/ubertooth-util.c15
14 files changed, 87 insertions, 3 deletions
diff --git a/host/libubertooth/src/ubertooth.c b/host/libubertooth/src/ubertooth.c
index 6b9297b..db8ddac 100644
--- a/host/libubertooth/src/ubertooth.c
+++ b/host/libubertooth/src/ubertooth.c
@@ -609,3 +609,24 @@ ubertooth_t* ubertooth_start(int ubertooth_device)
return ut;
}
+
+int ubertooth_check_api(ubertooth_t *ut) {
+ int r;
+
+ r = cmd_api_version(ut->devh);
+ if (r < 0) {
+ fprintf(stderr, "Ubertooth running very old firmware found.\n");
+ fprintf(stderr, "Please upgrade to latest released firmware.\n");
+ ubertooth_stop(ut);
+ return -1;
+ }
+ else if (r < UBERTOOTH_API_VERSION) {
+ fprintf(stderr, "Ubertooth API version %d found, libubertooth requires %d.\n",
+ r, UBERTOOTH_API_VERSION);
+ fprintf(stderr, "Please upgrade to latest released firmware.\n");
+ ubertooth_stop(ut);
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/host/libubertooth/src/ubertooth.h b/host/libubertooth/src/ubertooth.h
index cab4de6..c6905fc 100644
--- a/host/libubertooth/src/ubertooth.h
+++ b/host/libubertooth/src/ubertooth.h
@@ -83,6 +83,7 @@ ubertooth_t* ubertooth_init();
int ubertooth_connect(ubertooth_t* ut, int ubertooth_device);
ubertooth_t* ubertooth_start(int ubertooth_device);
void ubertooth_stop(ubertooth_t* ut);
+int ubertooth_check_api(ubertooth_t *ut);
void ubertooth_set_timeout(ubertooth_t* ut, int seconds);
int ubertooth_bulk_init(ubertooth_t* ut);
diff --git a/host/libubertooth/src/ubertooth_control.c b/host/libubertooth/src/ubertooth_control.c
index f849eac..219ceeb 100644
--- a/host/libubertooth/src/ubertooth_control.c
+++ b/host/libubertooth/src/ubertooth_control.c
@@ -996,6 +996,19 @@ int cmd_hop(struct libusb_device_handle* devh)
return 0;
}
+int32_t cmd_api_version(struct libusb_device_handle* devh) {
+ unsigned char data[4];
+ int r;
+
+ r = libusb_control_transfer(devh, CTRL_IN, UBERTOOTH_GET_API_VERSION, 0, 0,
+ data, 4, 3000);
+ if (r < 0) {
+ show_libusb_error(r);
+ return r;
+ }
+ return data[0] | data[1] << 8 | data[2] << 16 | data[3] << 24;
+}
+
int ubertooth_cmd_sync(struct libusb_device_handle* devh,
uint8_t type,
uint8_t command,
diff --git a/host/libubertooth/src/ubertooth_control.h b/host/libubertooth/src/ubertooth_control.h
index 2892f50..9740ecc 100644
--- a/host/libubertooth/src/ubertooth_control.h
+++ b/host/libubertooth/src/ubertooth_control.h
@@ -145,5 +145,6 @@ int cmd_set_jam_mode(struct libusb_device_handle* devh, int mode);
int cmd_ego(struct libusb_device_handle* devh, int mode);
int cmd_afh(struct libusb_device_handle* devh);
int cmd_hop(struct libusb_device_handle* devh);
+int32_t cmd_api_version(struct libusb_device_handle* devh);
#endif /* __UBERTOOTH_CONTROL_H__ */
diff --git a/host/libubertooth/src/ubertooth_interface.h b/host/libubertooth/src/ubertooth_interface.h
index 5facc22..f30d99d 100644
--- a/host/libubertooth/src/ubertooth_interface.h
+++ b/host/libubertooth/src/ubertooth_interface.h
@@ -24,6 +24,9 @@
#include <stdint.h>
+// increment on every API change
+#define UBERTOOTH_API_VERSION 0
+
#define DMA_SIZE 50
#define NUM_BREDR_CHANNELS 79
@@ -100,6 +103,7 @@ enum ubertooth_usb_commands {
UBERTOOTH_AFH = 61,
UBERTOOTH_HOP = 62,
UBERTOOTH_TRIM_CLOCK = 63,
+ UBERTOOTH_GET_API_VERSION = 64,
};
enum jam_modes {
diff --git a/host/ubertooth-tools/src/ubertooth-afh.c b/host/ubertooth-tools/src/ubertooth-afh.c
index fd81d4b..202ea1d 100644
--- a/host/ubertooth-tools/src/ubertooth-afh.c
+++ b/host/ubertooth-tools/src/ubertooth-afh.c
@@ -57,6 +57,7 @@ int main(int argc, char* argv[])
uint8_t use_r_format = 0;
ubertooth_t* ut = NULL;
+ int r;
while ((opt=getopt(argc,argv,"rhVl:u:U:e:a:t:m:")) != EOF) {
switch(opt) {
@@ -124,6 +125,10 @@ int main(int argc, char* argv[])
return 1;
}
+ r = ubertooth_check_api(ut);
+ if (r < 0)
+ return 1;
+
/* Clean up on exit. */
register_cleanup_handler(ut);
diff --git a/host/ubertooth-tools/src/ubertooth-btle.c b/host/ubertooth-tools/src/ubertooth-btle.c
index fbbc89a..b026130 100644
--- a/host/ubertooth-tools/src/ubertooth-btle.c
+++ b/host/ubertooth-tools/src/ubertooth-btle.c
@@ -237,6 +237,10 @@ int main(int argc, char *argv[])
return 1;
}
+ r = ubertooth_check_api(ut);
+ if (r < 0)
+ return 1;
+
/* Clean up on exit. */
register_cleanup_handler(ut);
diff --git a/host/ubertooth-tools/src/ubertooth-dump.c b/host/ubertooth-tools/src/ubertooth-dump.c
index feb6850..8fcb8cd 100644
--- a/host/ubertooth-tools/src/ubertooth-dump.c
+++ b/host/ubertooth-tools/src/ubertooth-dump.c
@@ -53,6 +53,7 @@ int main(int argc, char *argv[])
char ubertooth_device = -1;
ubertooth_t* ut = NULL;
+ int r;
while ((opt=getopt(argc,argv,"bhclU:d:")) != EOF) {
switch(opt) {
@@ -89,6 +90,10 @@ int main(int argc, char *argv[])
return 1;
}
+ r = ubertooth_check_api(ut);
+ if (r < 0)
+ return 1;
+
/* Clean up on exit. */
register_cleanup_handler(ut);
diff --git a/host/ubertooth-tools/src/ubertooth-ego.c b/host/ubertooth-tools/src/ubertooth-ego.c
index fe6704e..0f8c5cc 100644
--- a/host/ubertooth-tools/src/ubertooth-ego.c
+++ b/host/ubertooth-tools/src/ubertooth-ego.c
@@ -84,6 +84,10 @@ int main(int argc, char *argv[])
return 1;
}
+ r = ubertooth_check_api(ut);
+ if (r < 0)
+ return 1;
+
/* Clean up on exit. */
register_cleanup_handler(ut);
diff --git a/host/ubertooth-tools/src/ubertooth-follow.c b/host/ubertooth-tools/src/ubertooth-follow.c
index 2e7ffb2..d3a4d01 100644
--- a/host/ubertooth-tools/src/ubertooth-follow.c
+++ b/host/ubertooth-tools/src/ubertooth-follow.c
@@ -225,6 +225,11 @@ int main(int argc, char *argv[])
usage();
return 1;
}
+
+ r = ubertooth_check_api(ut);
+ if (r < 0)
+ return 1;
+
cmd_set_bdaddr(ut->devh, btbb_piconet_get_bdaddr(pn));
if(afh_enabled)
cmd_set_afh_map(ut->devh, afh_map);
diff --git a/host/ubertooth-tools/src/ubertooth-rx.c b/host/ubertooth-tools/src/ubertooth-rx.c
index dcd3fb3..ba92ab7 100644
--- a/host/ubertooth-tools/src/ubertooth-rx.c
+++ b/host/ubertooth-tools/src/ubertooth-rx.c
@@ -149,6 +149,10 @@ int main(int argc, char* argv[])
return 1;
}
+ r = ubertooth_check_api(ut);
+ if (r < 0)
+ return 1;
+
r = btbb_init(max_ac_errors);
if (r < 0)
return r;
diff --git a/host/ubertooth-tools/src/ubertooth-scan.c b/host/ubertooth-tools/src/ubertooth-scan.c
index 23f6596..502d2ba 100644
--- a/host/ubertooth-tools/src/ubertooth-scan.c
+++ b/host/ubertooth-tools/src/ubertooth-scan.c
@@ -239,6 +239,10 @@ int main(int argc, char *argv[])
usage();
return 1;
}
+ r = ubertooth_check_api(ut);
+ if (r < 0)
+ return 1;
+
/* Set sweep mode - otherwise AFH map is useless */
cmd_set_channel(ut->devh, 9999);
diff --git a/host/ubertooth-tools/src/ubertooth-specan.c b/host/ubertooth-tools/src/ubertooth-specan.c
index d1b3a92..72021d9 100644
--- a/host/ubertooth-tools/src/ubertooth-specan.c
+++ b/host/ubertooth-tools/src/ubertooth-specan.c
@@ -147,6 +147,10 @@ int main(int argc, char *argv[])
return 1;
}
+ r = ubertooth_check_api(ut);
+ if (r < 0)
+ return 1;
+
/* Clean up on exit. */
register_cleanup_handler(ut);
diff --git a/host/ubertooth-tools/src/ubertooth-util.c b/host/ubertooth-tools/src/ubertooth-util.c
index 21f5349..0e8adc0 100644
--- a/host/ubertooth-tools/src/ubertooth-util.c
+++ b/host/ubertooth-tools/src/ubertooth-util.c
@@ -71,7 +71,7 @@ int main(int argc, char *argv[])
int do_range_test, do_repeater, do_firmware, do_board_id;
int do_range_result, do_all_leds, do_identify;
int do_set_squelch, do_get_squelch, squelch_level;
- int do_something, do_compile_info;
+ int do_something, do_compile_info, do_api_check;
char ubertooth_device = -1;
/* set command states to negative as a starter
@@ -82,9 +82,9 @@ int main(int argc, char *argv[])
do_range_test= do_repeater= do_firmware= do_board_id= -1;
do_range_result= do_all_leds= do_identify= -1;
do_set_squelch= -1, do_get_squelch= -1; squelch_level= 0;
- do_something= 0; do_compile_info= -1;
+ do_something= 0; do_compile_info= -1, do_api_check = 0;
- while ((opt=getopt(argc,argv,"U:hnmefiIprsStvbl::a::C::c::d::q::z::9V")) != EOF) {
+ while ((opt=getopt(argc,argv,"U:hnmefiIprsStvbl::a::C::c::d::q::z::9VA")) != EOF) {
switch(opt) {
case 'U':
ubertooth_device = atoi(optarg);
@@ -180,6 +180,9 @@ int main(int argc, char *argv[])
case 'V':
do_compile_info = 0;
break;
+ case 'A':
+ do_api_check = 1;
+ break;
case 'h':
default:
usage();
@@ -320,6 +323,12 @@ int main(int argc, char *argv[])
r = cmd_get_squelch(ut->devh);
printf("Squelch set to %d\n", (int8_t)r);
}
+ if (do_api_check) {
+ r = ubertooth_check_api(ut);
+ if (r == 0) {
+ printf("Ubertooth is running latest API (%d)\n", UBERTOOTH_API_VERSION);
+ }
+ }
if(do_something) {
unsigned char buf[4] = { 0x55, 0x55, 0x55, 0x55 };
cmd_do_something(ut->devh, NULL, 0);