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


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38265 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe
2010-08-19 15:29:02 +00:00
parent e2fc6dba84
commit 269ebc04b9
14 changed files with 77 additions and 78 deletions
+2 -17
View File
@@ -1198,6 +1198,7 @@ if $(HAIKU_NO_WERROR) != 1 {
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 @@ if $(HAIKU_NO_WERROR) != 1 {
# 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 ;
}
+4 -4
View File
@@ -34,15 +34,15 @@ public:
}
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)
+3 -3
View File
@@ -25,9 +25,9 @@ typedef struct {
} __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
+17 -9
View File
@@ -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 @@ typedef enum _connection_status {
HCI_CONN_OPEN,
} connection_status;
#ifdef __cplusplus
struct HciConnection : DoublyLinkedListLinkImpl<HciConnection> {
@@ -138,12 +142,12 @@ struct bluetooth_core_data_module_info {
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 @@ struct bluetooth_core_data_module_info {
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 bluetooth_core_data_module_info {
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
@@ -19,7 +19,7 @@ net_buffer_module_info* gBufferModule = NULL;
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 @@ PostEvent(bluetooth_device* ndev, void* event, size_t size)
// 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");
@@ -37,7 +37,7 @@ HciConnection::~HciConnection()
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 @@ AddConnection(uint16 handle, int type, bdaddr_t* dst, hci_id hid)
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 @@ bail:
status_t
RemoveConnection(bdaddr_t* destination, hci_id hid)
RemoveConnection(const bdaddr_t& destination, hci_id hid)
{
HciConnection* conn;
@@ -83,7 +83,7 @@ RemoveConnection(bdaddr_t* destination, hci_id hid)
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 @@ RemoveConnection(uint16 handle, hci_id hid)
hci_id
RouteConnection(const bdaddr_t* destination) {
RouteConnection(const bdaddr_t& destination) {
HciConnection* conn;
@@ -138,7 +138,7 @@ RouteConnection(const bdaddr_t* destination) {
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 @@ ConnectionByHandle(uint16 handle, hci_id hid)
HciConnection*
ConnectionByDestination(const bdaddr_t* destination, hci_id hid)
ConnectionByDestination(const bdaddr_t& destination, hci_id hid)
{
HciConnection* conn;
@@ -177,7 +177,7 @@ ConnectionByDestination(const bdaddr_t* destination, hci_id hid)
conn = iterator.Next();
if (conn->Hid == hid
&& bdaddrUtils::Compare(&conn->destination, destination)) {
&& bdaddrUtils::Compare(conn->destination, destination)) {
return conn;
}
}
@@ -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);
@@ -237,14 +237,14 @@ L2capEndpoint::Connect(const struct sockaddr* _address)
// 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);
@@ -95,7 +95,7 @@ l2cap_is_empty_address(const sockaddr *address, bool checkPort)
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 @@ l2cap_equal_addresses(const sockaddr *a, const sockaddr *b)
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 @@ l2cap_equal_addresses_and_ports(const sockaddr *a, const sockaddr *b)
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 @@ l2cap_update_to(sockaddr *_address, const sockaddr *_from)
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;
+24 -15
View File
@@ -45,7 +45,7 @@ DiscoveryListener::InquiryCompleted(int discType)
/* 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 @@ DiscoveryListener::MessageReceived(BMessage* message)
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();
if (bdaddrUtils::Compare((bdaddr_t*) &inquiryInfo->bdaddr, &b1)) {
for (int32 index = 0 ; index < fRemoteDevicesList.CountItems();
index++) {
bdaddr_t b1 = fRemoteDevicesList.ItemAt(index)
->GetBluetoothAddress();
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 @@ DiscoveryListener::MessageReceived(BMessage* message)
}
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 @@ DiscoveryListener::MessageReceived(BMessage* message)
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::MessageReceived(BMessage* message)
}
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();
+2 -4
View File
@@ -115,9 +115,7 @@ RemoteDevice::GetBluetoothAddress()
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 @@ RemoteDevice::Authenticate()
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!
+1 -2
View File
@@ -143,8 +143,7 @@ DeviceListItem::Compare(const void *firstArg, const void *secondArg)
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);
}
+1 -1
View File
@@ -509,7 +509,7 @@ BluetoothServer::SDPServerThread(void* data)
// 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);
+1 -1
View File
@@ -975,7 +975,7 @@ LocalDeviceImpl::LinkKeyRequested(struct hci_ev_link_key_req* keyRequested,
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) {