Date: Fri, 29 May 2009 20:25:03 +0000 (UTC) From: Maksim Yevmenkin <emax@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org Subject: svn commit: r193061 - stable/7/lib/libbluetooth Message-ID: <200905292025.n4TKP3f2085801@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: emax Date: Fri May 29 20:25:03 2009 New Revision: 193061 URL: http://svn.freebsd.org/changeset/base/193061 Log: MFC r192113 Avoid floating point arithmetic while calculating iquiry length. Submitted by: Iain Hibbert < plunky -at- rya-online -dot- net > Modified: stable/7/lib/libbluetooth/ (props changed) stable/7/lib/libbluetooth/hci.c Modified: stable/7/lib/libbluetooth/hci.c ============================================================================== --- stable/7/lib/libbluetooth/hci.c Fri May 29 20:22:56 2009 (r193060) +++ stable/7/lib/libbluetooth/hci.c Fri May 29 20:25:03 2009 (r193061) @@ -410,7 +410,6 @@ bt_devinquiry(char const *devname, time_ 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_ 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 + */ + + if (length <= 0) + length = 5; + else if (length == 1) + length = 2; + else if (length > 62) + length = 62; - to = (time_t)((double) cp->inquiry_length * 1.28) + 1; + 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_ 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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905292025.n4TKP3f2085801>