Author: zooey Date: 2010-08-19 17:29:02 +0200 (Thu, 19 Aug 2010) New Revision: 38265 Changeset: http://dev.haiku-os.org/changeset/38265 Ticket: http://dev.haiku-os.org/ticket/6373 Modified: haiku/trunk/build/jam/BuildSetup haiku/trunk/headers/os/bluetooth/bdaddrUtils.h haiku/trunk/headers/os/bluetooth/bluetooth.h haiku/trunk/headers/private/bluetooth/btCoreData.h haiku/trunk/src/add-ons/kernel/bluetooth/btCoreData/BTCoreData.cpp haiku/trunk/src/add-ons/kernel/bluetooth/btCoreData/ConnectionInterface.cpp haiku/trunk/src/add-ons/kernel/bluetooth/btCoreData/ConnectionInterface.h haiku/trunk/src/add-ons/kernel/network/protocols/l2cap/L2capEndpoint.cpp haiku/trunk/src/add-ons/kernel/network/protocols/l2cap/l2cap_address.cpp haiku/trunk/src/kits/bluetooth/DiscoveryListener.cpp haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp haiku/trunk/src/preferences/bluetooth/DeviceListItem.cpp haiku/trunk/src/servers/bluetooth/BluetoothServer.cpp haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp Log: Fix #6373, second try * make BDADDR_* macros refer to value types instead of addresses * adjust all interfaces using bdaddr_t* to use (mostly const) refs instead, which IMHO makes the interface & code clearer * that got rid of a couple of const incorrectness casts * some cleanup along the way Modified: haiku/trunk/build/jam/BuildSetup =================================================================== --- haiku/trunk/build/jam/BuildSetup 2010-08-19 14:56:03 UTC (rev 38264) +++ haiku/trunk/build/jam/BuildSetup 2010-08-19 15:29:02 UTC (rev 38265) @@ -1198,6 +1198,7 @@ EnableWerror src add-ons input_server devices ; # EnableWerror src add-ons input_server filters ; # EnableWerror src add-ons input_server methods ; + EnableWerror src add-ons kernel bluetooth ; # EnableWerror src add-ons kernel bus_managers acpi ; EnableWerror src add-ons kernel bus_managers agp_gart ; EnableWerror src add-ons kernel bus_managers ata ; @@ -1391,23 +1392,7 @@ # EnableWerror src kits tracker ; EnableWerror src kits translation ; EnableWerror src preferences ; - EnableWerror src servers app ; -# EnableWerror src servers bluetooth ; - EnableWerror src servers cddb_daemon ; - EnableWerror src servers debug ; - EnableWerror src servers input ; - EnableWerror src servers mail ; - EnableWerror src servers media ; - EnableWerror src servers media_addon ; - EnableWerror src servers midi ; - EnableWerror src servers mount ; - EnableWerror src servers net ; - EnableWerror src servers notification ; - EnableWerror src servers power ; - EnableWerror src servers print ; - EnableWerror src servers registrar ; - EnableWerror src servers services_daemon ; - EnableWerror src servers syslog_daemon ; + EnableWerror src servers ; EnableWerror src system kernel ; EnableWerror src system runtime_loader ; } Modified: haiku/trunk/headers/os/bluetooth/bdaddrUtils.h =================================================================== --- haiku/trunk/headers/os/bluetooth/bdaddrUtils.h 2010-08-19 14:56:03 UTC (rev 38264) +++ haiku/trunk/headers/os/bluetooth/bdaddrUtils.h 2010-08-19 15:29:02 UTC (rev 38265) @@ -34,15 +34,15 @@ } - static bool Compare(const bdaddr_t* ba1, const bdaddr_t* ba2) + static bool Compare(const bdaddr_t& ba1, const bdaddr_t& ba2) { - return (memcmp(ba1, ba2, sizeof(bdaddr_t)) == 0); + return (memcmp(&ba1, &ba2, sizeof(bdaddr_t)) == 0); } - static void Copy(bdaddr_t* dst, const bdaddr_t* src) + static void Copy(bdaddr_t& dst, const bdaddr_t& src) { - memcpy(dst, src, sizeof(bdaddr_t)); + memcpy(&dst, &src, sizeof(bdaddr_t)); } static char* ToString(const bdaddr_t bdaddr) Modified: haiku/trunk/headers/os/bluetooth/bluetooth.h =================================================================== --- haiku/trunk/headers/os/bluetooth/bluetooth.h 2010-08-19 14:56:03 UTC (rev 38264) +++ haiku/trunk/headers/os/bluetooth/bluetooth.h 2010-08-19 15:29:02 UTC (rev 38265) @@ -25,9 +25,9 @@ } __attribute__((packed)) bdaddr_t; -#define BDADDR_NULL (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}}) -#define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}}) -#define BDADDR_BROADCAST (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}) +#define BDADDR_NULL ((bdaddr_t) {{0, 0, 0, 0, 0, 0}}) +#define BDADDR_LOCAL ((bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}}) +#define BDADDR_BROADCAST ((bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}) #define BDADDR_ANY BDADDR_BROADCAST Modified: haiku/trunk/headers/private/bluetooth/btCoreData.h =================================================================== --- haiku/trunk/headers/private/bluetooth/btCoreData.h 2010-08-19 14:56:03 UTC (rev 38264) +++ haiku/trunk/headers/private/bluetooth/btCoreData.h 2010-08-19 15:29:02 UTC (rev 38265) @@ -5,6 +5,7 @@ #ifndef _BTCOREDATA_H #define _BTCOREDATA_H + #include <module.h> #include <lock.h> #include <util/DoublyLinkedList.h> @@ -18,8 +19,10 @@ #include <bluetooth/HCI/btHCI_transport.h> #include <l2cap.h> + #define BT_CORE_DATA_MODULE_NAME "bluetooth/btCoreData/v1" + struct L2capChannel; struct L2capFrame; struct L2capEndpoint; @@ -29,6 +32,7 @@ HCI_CONN_OPEN, } connection_status; + #ifdef __cplusplus struct HciConnection : DoublyLinkedListLinkImpl<HciConnection> { @@ -138,12 +142,12 @@ status_t (*PostEvent)(bluetooth_device* ndev, void* event, size_t size); struct HciConnection* (*AddConnection)(uint16 handle, int type, - bdaddr_t* dst, hci_id hid); + const bdaddr_t& dst, hci_id hid); // status_t (*RemoveConnection)(bdaddr_t destination, hci_id hid); status_t (*RemoveConnection)(uint16 handle, hci_id hid); - hci_id (*RouteConnection)(const bdaddr_t* destination); + hci_id (*RouteConnection)(const bdaddr_t& destination); void (*SetAclBuffer)(struct HciConnection* conn, net_buffer* nbuf); @@ -155,8 +159,8 @@ bool (*AclOverFlowed)(struct HciConnection* conn); struct HciConnection* (*ConnectionByHandle)(uint16 handle, hci_id hid); - struct HciConnection* (*ConnectionByDestination)(const bdaddr_t* destination, - hci_id hid); + struct HciConnection* (*ConnectionByDestination)( + const bdaddr_t& destination, hci_id hid); struct L2capChannel* (*AddChannel)(struct HciConnection* conn, uint16 psm); @@ -169,20 +173,24 @@ struct L2capFrame* (*SignalByIdent)(struct HciConnection* conn, uint8 ident); - status_t (*TimeoutSignal)(struct L2capFrame* frame, uint32 timeo); + status_t (*TimeoutSignal)(struct L2capFrame* frame, + uint32 timeo); status_t (*UnTimeoutSignal)(struct L2capFrame* frame); struct L2capFrame* (*SpawnFrame)(struct HciConnection* conn, - struct L2capChannel* channel, net_buffer* buffer, frame_type frame); + struct L2capChannel* channel, + net_buffer* buffer, frame_type frame); struct L2capFrame* (*SpawnSignal)(struct HciConnection* conn, - struct L2capChannel* channel, net_buffer* buffer, - uint8 ident, uint8 code); + struct L2capChannel* channel, + net_buffer* buffer, uint8 ident, uint8 code); status_t (*AcknowledgeSignal)(struct L2capFrame* frame); status_t (*QueueSignal)(struct L2capFrame* frame); }; -inline bool ExistConnectionByDestination(bdaddr_t* destination, hci_id hid); +inline bool ExistConnectionByDestination(const bdaddr_t& destination, + hci_id hid); inline bool ExistConnectionByHandle(uint16 handle, hci_id hid); + #endif // _BTCOREDATA_H Modified: haiku/trunk/src/add-ons/kernel/bluetooth/btCoreData/BTCoreData.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/bluetooth/btCoreData/BTCoreData.cpp 2010-08-19 14:56:03 UTC (rev 38264) +++ haiku/trunk/src/add-ons/kernel/bluetooth/btCoreData/BTCoreData.cpp 2010-08-19 15:29:02 UTC (rev 38265) @@ -19,7 +19,7 @@ inline bool -ExistConnectionByDestination(bdaddr_t* destination, hci_id hid = -1) +ExistConnectionByDestination(const bdaddr_t& destination, hci_id hid = -1) { return (ConnectionByDestination(destination, hid) != NULL); } @@ -102,7 +102,7 @@ // TODO: XXX parse handle field HciConnection* conn = AddConnection(data->handle, BT_ACL, - &data->bdaddr, ndev->index); + data->bdaddr, ndev->index); if (conn == NULL) panic("no mem for conn desc"); Modified: haiku/trunk/src/add-ons/kernel/bluetooth/btCoreData/ConnectionInterface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/bluetooth/btCoreData/ConnectionInterface.cpp 2010-08-19 14:56:03 UTC (rev 38264) +++ haiku/trunk/src/add-ons/kernel/bluetooth/btCoreData/ConnectionInterface.cpp 2010-08-19 15:29:02 UTC (rev 38265) @@ -37,7 +37,7 @@ HciConnection* -AddConnection(uint16 handle, int type, bdaddr_t* dst, hci_id hid) +AddConnection(uint16 handle, int type, const bdaddr_t& dst, hci_id hid) { // Create connection descriptor @@ -55,7 +55,7 @@ conn->currentRxExpectedLength = 0; update: // fill values - bdaddrUtils::Copy(&conn->destination, dst); + bdaddrUtils::Copy(conn->destination, dst); conn->type = type; conn->handle = handle; conn->Hid = hid; @@ -72,7 +72,7 @@ status_t -RemoveConnection(bdaddr_t* destination, hci_id hid) +RemoveConnection(const bdaddr_t& destination, hci_id hid) { HciConnection* conn; @@ -83,7 +83,7 @@ conn = iterator.Next(); if (conn->Hid == hid - && bdaddrUtils::Compare(&conn->destination, destination)) { + && bdaddrUtils::Compare(conn->destination, destination)) { // if the device is still part of the list, remove it if (conn->GetDoublyLinkedListLink()->next != NULL @@ -129,7 +129,7 @@ hci_id -RouteConnection(const bdaddr_t* destination) { +RouteConnection(const bdaddr_t& destination) { HciConnection* conn; @@ -138,7 +138,7 @@ while (iterator.HasNext()) { conn = iterator.Next(); - if (bdaddrUtils::Compare(&conn->destination, destination)) { + if (bdaddrUtils::Compare(conn->destination, destination)) { return conn->Hid; } } @@ -167,7 +167,7 @@ HciConnection* -ConnectionByDestination(const bdaddr_t* destination, hci_id hid) +ConnectionByDestination(const bdaddr_t& destination, hci_id hid) { HciConnection* conn; @@ -177,7 +177,7 @@ conn = iterator.Next(); if (conn->Hid == hid - && bdaddrUtils::Compare(&conn->destination, destination)) { + && bdaddrUtils::Compare(conn->destination, destination)) { return conn; } } Modified: haiku/trunk/src/add-ons/kernel/bluetooth/btCoreData/ConnectionInterface.h =================================================================== --- haiku/trunk/src/add-ons/kernel/bluetooth/btCoreData/ConnectionInterface.h 2010-08-19 14:56:03 UTC (rev 38264) +++ haiku/trunk/src/add-ons/kernel/bluetooth/btCoreData/ConnectionInterface.h 2010-08-19 15:29:02 UTC (rev 38265) @@ -15,16 +15,16 @@ extern DoublyLinkedList<HciConnection> sConnectionList; HciConnection* ConnectionByHandle(uint16 handle, hci_id hid); -HciConnection* ConnectionByDestination(const bdaddr_t* destination, +HciConnection* ConnectionByDestination(const bdaddr_t& destination, hci_id hid); -HciConnection* AddConnection(uint16 handle, int type, bdaddr_t* dst, +HciConnection* AddConnection(uint16 handle, int type, const bdaddr_t& dst, hci_id hid); -status_t RemoveConnection(bdaddr_t* destination, hci_id hid); +status_t RemoveConnection(const bdaddr_t& destination, hci_id hid); status_t RemoveConnection(uint16 handle, hci_id hid); -hci_id RouteConnection(const bdaddr_t* destination); +hci_id RouteConnection(const bdaddr_t& destination); void SetAclBuffer(HciConnection* conn, net_buffer* nbuf); void SetAclExpectedSize(HciConnection* conn, size_t size); Modified: haiku/trunk/src/add-ons/kernel/network/protocols/l2cap/L2capEndpoint.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/l2cap/L2capEndpoint.cpp 2010-08-19 14:56:03 UTC (rev 38264) +++ haiku/trunk/src/add-ons/kernel/network/protocols/l2cap/L2capEndpoint.cpp 2010-08-19 15:29:02 UTC (rev 38265) @@ -237,14 +237,14 @@ // TODO: If we were bound to a specific source address // Route, we must find a Connection descriptor with address->l2cap_address - hci_id hid = btCoreData->RouteConnection(&address->l2cap_bdaddr); + hci_id hid = btCoreData->RouteConnection(address->l2cap_bdaddr); debugf("%lx for route %s\n", hid, bdaddrUtils::ToString(address->l2cap_bdaddr)); if (hid > 0) { HciConnection* connection = btCoreData->ConnectionByDestination( - &address->l2cap_bdaddr, hid); + address->l2cap_bdaddr, hid); L2capChannel* channel = btCoreData->AddChannel(connection, address->l2cap_psm); Modified: haiku/trunk/src/add-ons/kernel/network/protocols/l2cap/l2cap_address.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/l2cap/l2cap_address.cpp 2010-08-19 14:56:03 UTC (rev 38264) +++ haiku/trunk/src/add-ons/kernel/network/protocols/l2cap/l2cap_address.cpp 2010-08-19 15:29:02 UTC (rev 38265) @@ -95,7 +95,7 @@ return true; return ((bdaddrUtils::Compare( - &((const sockaddr_l2cap *)address)->l2cap_bdaddr, BDADDR_NULL)==0) + ((const sockaddr_l2cap *)address)->l2cap_bdaddr, BDADDR_NULL)==0) && (!checkPort || ((sockaddr_l2cap *)address)->l2cap_psm == 0)); } @@ -127,8 +127,8 @@ if (a == NULL && b != NULL) return l2cap_is_empty_address(b, false); - return bdaddrUtils::Compare(&((const sockaddr_l2cap*)a)->l2cap_bdaddr, - &((sockaddr_l2cap*)b)->l2cap_bdaddr); + return bdaddrUtils::Compare(((const sockaddr_l2cap*)a)->l2cap_bdaddr, + ((sockaddr_l2cap*)b)->l2cap_bdaddr); } @@ -159,8 +159,8 @@ if (a == NULL && b != NULL) return l2cap_is_empty_address(b, true); - return (bdaddrUtils::Compare(&((const sockaddr_l2cap *)a)->l2cap_bdaddr, - &((const sockaddr_l2cap *)b)->l2cap_bdaddr)) + return (bdaddrUtils::Compare(((const sockaddr_l2cap *)a)->l2cap_bdaddr, + ((const sockaddr_l2cap *)b)->l2cap_bdaddr)) && ((sockaddr_l2cap *)a)->l2cap_psm == ((sockaddr_l2cap *)b)->l2cap_psm; } @@ -329,7 +329,7 @@ if (address->l2cap_psm == 0) address->l2cap_psm = from->l2cap_psm; - if (bdaddrUtils::Compare(&address->l2cap_bdaddr, BDADDR_BROADCAST)) + if (bdaddrUtils::Compare(address->l2cap_bdaddr, BDADDR_BROADCAST)) address->l2cap_bdaddr = from->l2cap_bdaddr; return B_OK; Modified: haiku/trunk/src/kits/bluetooth/DiscoveryListener.cpp =================================================================== --- haiku/trunk/src/kits/bluetooth/DiscoveryListener.cpp 2010-08-19 14:56:03 UTC (rev 38264) +++ haiku/trunk/src/kits/bluetooth/DiscoveryListener.cpp 2010-08-19 15:29:02 UTC (rev 38265) @@ -45,7 +45,7 @@ /* private */ /* A LocalDevice is always referenced in any request to the - * Bluetooth server therefore is going to be needed in any + * Bluetooth server therefore is going to be needed in any */ void DiscoveryListener::SetLocalDeviceOwner(LocalDevice* ld) @@ -73,21 +73,26 @@ ssize_t size; RemoteDevice* rd = NULL; bool duplicatedFound = false; - + // TODO: Loop for all inquiryInfo! - if (message->FindData("info", B_ANY_TYPE, 0, (const void**)&inquiryInfo, &size) == B_OK) { + if (message->FindData("info", B_ANY_TYPE, 0, + (const void**)&inquiryInfo, &size) == B_OK) { // Skip duplicated replies - for (int32 index = 0 ; index < fRemoteDevicesList.CountItems(); index++) { - - bdaddr_t b1 = fRemoteDevicesList.ItemAt(index)->GetBluetoothAddress(); + for (int32 index = 0 ; index < fRemoteDevicesList.CountItems(); + index++) { + bdaddr_t b1 = fRemoteDevicesList.ItemAt(index) + ->GetBluetoothAddress(); - if (bdaddrUtils::Compare((bdaddr_t*) &inquiryInfo->bdaddr, &b1)) { - + if (bdaddrUtils::Compare(inquiryInfo->bdaddr, b1)) { // update these values - fRemoteDevicesList.ItemAt(index)->fPageRepetitionMode = inquiryInfo->pscan_rep_mode; - fRemoteDevicesList.ItemAt(index)->fScanPeriodMode = inquiryInfo->pscan_period_mode; - fRemoteDevicesList.ItemAt(index)->fScanMode = inquiryInfo->pscan_mode; - fRemoteDevicesList.ItemAt(index)->fClockOffset = inquiryInfo->clock_offset; + fRemoteDevicesList.ItemAt(index)->fPageRepetitionMode + = inquiryInfo->pscan_rep_mode; + fRemoteDevicesList.ItemAt(index)->fScanPeriodMode + = inquiryInfo->pscan_period_mode; + fRemoteDevicesList.ItemAt(index)->fScanMode + = inquiryInfo->pscan_mode; + fRemoteDevicesList.ItemAt(index)->fClockOffset + = inquiryInfo->clock_offset; duplicatedFound = true; break; @@ -95,7 +100,8 @@ } if (!duplicatedFound) { - rd = new RemoteDevice(inquiryInfo->bdaddr, (uint8*)inquiryInfo->dev_class); + rd = new RemoteDevice(inquiryInfo->bdaddr, + (uint8*)inquiryInfo->dev_class); fRemoteDevicesList.AddItem(rd); // keep all inquiry reported data rd->SetLocalDeviceOwner(fLocalDevice); @@ -124,7 +130,7 @@ case BT_MSG_INQUIRY_TERMINATED: /* inquiry was cancelled */ InquiryCompleted(BT_INQUIRY_TERMINATED); break; - + case BT_MSG_INQUIRY_ERROR: InquiryCompleted(BT_INQUIRY_ERROR); break; @@ -136,7 +142,10 @@ } -DiscoveryListener::DiscoveryListener() : BLooper() , fRemoteDevicesList(BT_MAX_RESPONSES) +DiscoveryListener::DiscoveryListener() + : + BLooper(), + fRemoteDevicesList(BT_MAX_RESPONSES) { // TODO: Make a better handling of the running not running state Run(); Modified: haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp =================================================================== --- haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp 2010-08-19 14:56:03 UTC (rev 38264) +++ haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp 2010-08-19 15:29:02 UTC (rev 38265) @@ -115,9 +115,7 @@ bool RemoteDevice::Equals(RemoteDevice* obj) { - bdaddr_t ba = obj->GetBluetoothAddress(); - - return bdaddrUtils::Compare(&fBdaddr, &ba); + return bdaddrUtils::Compare(fBdaddr, obj->GetBluetoothAddress()); } @@ -135,7 +133,7 @@ BluetoothCommand<typed_command(hci_cp_create_conn)> createConnection(OGF_LINK_CONTROL, OCF_CREATE_CONN); - bdaddrUtils::Copy(&createConnection->bdaddr, &fBdaddr); + bdaddrUtils::Copy(createConnection->bdaddr, fBdaddr); createConnection->pscan_rep_mode = fPageRepetitionMode; createConnection->pscan_mode = fScanMode; // Reserved in spec 2.1 createConnection->clock_offset = fClockOffset | 0x8000; // substract! Modified: haiku/trunk/src/preferences/bluetooth/DeviceListItem.cpp =================================================================== --- haiku/trunk/src/preferences/bluetooth/DeviceListItem.cpp 2010-08-19 14:56:03 UTC (rev 38264) +++ haiku/trunk/src/preferences/bluetooth/DeviceListItem.cpp 2010-08-19 15:29:02 UTC (rev 38265) @@ -143,8 +143,7 @@ const DeviceListItem* item2 = *static_cast<const DeviceListItem* const *> (secondArg); - return (int)bdaddrUtils::Compare((bdaddr_t*)&item1->fAddress, - (bdaddr_t*)&item2->fAddress); + return (int)bdaddrUtils::Compare(item1->fAddress, item2->fAddress); } Modified: haiku/trunk/src/servers/bluetooth/BluetoothServer.cpp =================================================================== --- haiku/trunk/src/servers/bluetooth/BluetoothServer.cpp 2010-08-19 14:56:03 UTC (rev 38264) +++ haiku/trunk/src/servers/bluetooth/BluetoothServer.cpp 2010-08-19 15:29:02 UTC (rev 38265) @@ -509,7 +509,7 @@ // bind socket to port 0x1001 of the first available // bluetooth adapter loc_addr.l2cap_family = AF_BLUETOOTH; - loc_addr.l2cap_bdaddr = *BDADDR_ANY; + loc_addr.l2cap_bdaddr = BDADDR_ANY; loc_addr.l2cap_psm = B_HOST_TO_LENDIAN_INT16(1); loc_addr.l2cap_len = sizeof(struct sockaddr_l2cap); Modified: haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp =================================================================== --- haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp 2010-08-19 14:56:03 UTC (rev 38264) +++ haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp 2010-08-19 15:29:02 UTC (rev 38265) @@ -975,7 +975,7 @@ BluetoothCommand<typed_command(hci_cp_link_key_neg_reply)> linkKeyNegativeReply(OGF_LINK_CONTROL, OCF_LINK_KEY_NEG_REPLY); - bdaddrUtils::Copy(&linkKeyNegativeReply->bdaddr, &keyRequested->bdaddr); + bdaddrUtils::Copy(linkKeyNegativeReply->bdaddr, keyRequested->bdaddr); if ((fHCIDelegate)->IssueCommand(linkKeyNegativeReply.Data(), linkKeyNegativeReply.Size()) == B_ERROR) {