aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMaksim Yevmenkin <emax@FreeBSD.org>2009-05-14 17:10:19 +0000
committerMaksim Yevmenkin <emax@FreeBSD.org>2009-05-14 17:10:19 +0000
commitb7ced94c8cd5fe9e1a73a2c0dec3e1e469a71259 (patch)
tree937c69a1e96912c61641ff47e55f163b9fa5a7f3 /lib
parenta72778d6faa695b2762f6bfeb3f067b24a916fb7 (diff)
downloadsrc-b7ced94c8cd5fe9e1a73a2c0dec3e1e469a71259.tar.gz
src-b7ced94c8cd5fe9e1a73a2c0dec3e1e469a71259.zip
Avoid floating point arithmetic while calculating iquiry length.
Submitted by: Iain Hibbert < plunky -at- rya-online -dot- net > MFC after: 1 week
Notes
Notes: svn path=/head/; revision=192113
Diffstat (limited to 'lib')
-rw-r--r--lib/libbluetooth/hci.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/lib/libbluetooth/hci.c b/lib/libbluetooth/hci.c
index 74c3e632ea8f..1ae6ff963d7b 100644
--- a/lib/libbluetooth/hci.c
+++ b/lib/libbluetooth/hci.c
@@ -410,7 +410,6 @@ bt_devinquiry(char const *devname, time_t length, int num_rsp,
ng_hci_inquiry_response *ir;
struct bt_devinquiry *i;
int s, n;
- time_t to;
if (ii == NULL) {
errno = EINVAL;
@@ -452,16 +451,20 @@ bt_devinquiry(char const *devname, time_t length, int num_rsp,
cp->lap[1] = 0x8b;
cp->lap[2] = 0x9e;
- /* Calculate inquire length in 1.28 second units */
- to = (time_t) ((double) length / 1.28);
- if (to <= 0)
- cp->inquiry_length = 4; /* 5.12 seconds */
- else if (to > 254)
- cp->inquiry_length = 255; /* 326.40 seconds */
- else
- cp->inquiry_length = to + 1;
+ /*
+ * Calculate inquire length in 1.28 second units
+ * v2.x specification says that 1.28 -> 61.44 seconds
+ * range is acceptable
+ */
- to = (time_t)((double) cp->inquiry_length * 1.28) + 1;
+ if (length <= 0)
+ length = 5;
+ else if (length == 1)
+ length = 2;
+ else if (length > 62)
+ length = 62;
+
+ cp->inquiry_length = (uint8_t)((length * 100) / 128);
if (num_rsp <= 0 || num_rsp > 255)
num_rsp = 8;
@@ -484,7 +487,7 @@ bt_devinquiry(char const *devname, time_t length, int num_rsp,
wait_for_more:
- n = bt_devrecv(s, buf, sizeof(buf), to);
+ n = bt_devrecv(s, buf, sizeof(buf), length);
if (n < 0) {
free(i);
bt_devclose(s);