Fix annoying warnings and provide an optimization.

This commit is contained in:
Andrew J. Kroll 2013-12-29 23:53:24 -05:00
parent 5426cb1fb6
commit 14fda1372c
5 changed files with 24 additions and 4 deletions

16
BTD.h
View file

@ -191,6 +191,22 @@
#define PAIR 1 #define PAIR 1
/* acl_handle_ok or it's a new connection */
#if 0
#define UHS_ACL_HANDLE_OK(x, y) ((uint16_t)(x[0]) | (uint16_t)(x[1] << 8)) == (y | 0x2000U)
#else
/*
* Better implementation.
* o One place for this code, it is reused four times in the source.
* Perhaps it is better as a function.
* o This should be faster since the && operation can early exit, this means
* the shift would only be performed if the first byte matches.
* o Casting is eliminated.
* o How does this compare in code size? No difference. It is a free optimization.
*/
#define UHS_ACL_HANDLE_OK(x, y) ((x[0] == (y & 0xff)) && (x[1] == ((y >> 8) | 0x20)))
#endif
/** All Bluetooth services should inherit this class. */ /** All Bluetooth services should inherit this class. */
class BluetoothService { class BluetoothService {
public: public:

View file

@ -67,7 +67,8 @@ void BTHID::ACLData(uint8_t* l2capinbuf) {
} }
} }
} }
if((l2capinbuf[0] | (uint16_t)l2capinbuf[1] << 8) == (hci_handle | 0x2000U)) { // acl_handle_ok or it's a new connection //if((l2capinbuf[0] | (uint16_t)l2capinbuf[1] << 8) == (hci_handle | 0x2000U)) { // acl_handle_ok or it's a new connection
if(UHS_ACL_HANDLE_OK(l2capinbuf, hci_handle)) { // acl_handle_ok or it's a new connection
if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { // l2cap_control - Channel ID for ACL-U if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { // l2cap_control - Channel ID for ACL-U
if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
#ifdef DEBUG_USB_HOST #ifdef DEBUG_USB_HOST

View file

@ -250,7 +250,8 @@ void PS3BT::ACLData(uint8_t* ACLData) {
} }
} }
} }
if((ACLData[0] | (uint16_t)ACLData[1] << 8) == (hci_handle | 0x2000U)) { //acl_handle_ok //if((ACLData[0] | (uint16_t)ACLData[1] << 8) == (hci_handle | 0x2000U)) { //acl_handle_ok
if(UHS_ACL_HANDLE_OK(ACLData, hci_handle)) { //acl_handle_ok
memcpy(l2capinbuf, ACLData, BULK_MAXPKTSIZE); memcpy(l2capinbuf, ACLData, BULK_MAXPKTSIZE);
if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { //l2cap_control - Channel ID for ACL-U if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { //l2cap_control - Channel ID for ACL-U
if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {

View file

@ -97,7 +97,8 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
} }
} }
} }
if((l2capinbuf[0] | (uint16_t)l2capinbuf[1] << 8) == (hci_handle | 0x2000U)) { // acl_handle_ok //if((l2capinbuf[0] | (uint16_t)l2capinbuf[1] << 8) == (hci_handle | 0x2000U)) { // acl_handle_ok
if(UHS_ACL_HANDLE_OK(l2capinbuf, hci_handle)) { // acl_handle_ok
if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { //l2cap_control - Channel ID for ACL-U if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { //l2cap_control - Channel ID for ACL-U
if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
#ifdef DEBUG_USB_HOST #ifdef DEBUG_USB_HOST

View file

@ -144,7 +144,8 @@ void WII::ACLData(uint8_t* l2capinbuf) {
} }
} }
} }
if((l2capinbuf[0] | (uint16_t)l2capinbuf[1] << 8) == (hci_handle | 0x2000U)) { // acl_handle_ok or it's a new connection //if((l2capinbuf[0] | (uint16_t)l2capinbuf[1] << 8) == (hci_handle | 0x2000U)) { // acl_handle_ok or it's a new connection
if(UHS_ACL_HANDLE_OK(l2capinbuf, hci_handle)) { // acl_handle_ok or it's a new connection
if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { //l2cap_control - Channel ID for ACL-U if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { //l2cap_control - Channel ID for ACL-U
if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
#ifdef DEBUG_USB_HOST #ifdef DEBUG_USB_HOST