diff --git a/headers/os/bluetooth/LocalDevice.h b/headers/os/bluetooth/LocalDevice.h index d4a80c4ff4..31ae2f4035 100644 --- a/headers/os/bluetooth/LocalDevice.h +++ b/headers/os/bluetooth/LocalDevice.h @@ -46,11 +46,11 @@ public: ServiceRecord getRecord(Connection notifier); void updateRecord(ServiceRecord srvRecord); */ - hci_id GetID(void) {return hid;} + hci_id ID() const; private: LocalDevice(hci_id hid); virtual ~LocalDevice(); - + status_t ReadLocalVersion(); status_t ReadBufferSize(); status_t Reset(); @@ -58,8 +58,7 @@ private: static LocalDevice* RequestLocalDeviceID(BMessage* request); BMessenger* fMessenger; - - hci_id hid; + hci_id fHid; friend class DiscoveryAgent; friend class RemoteDevice; diff --git a/src/kits/bluetooth/DeviceClass.cpp b/src/kits/bluetooth/DeviceClass.cpp index ab3e81595c..ff445010ce 100644 --- a/src/kits/bluetooth/DeviceClass.cpp +++ b/src/kits/bluetooth/DeviceClass.cpp @@ -13,9 +13,9 @@ DeviceClass::GetServiceClass(BString& serviceClass) static const char *services[] = { "Positioning", "Networking", "Rendering", "Capturing", "Object Transfer", "Audio", "Telephony", "Information" }; - + if (GetServiceClass() != 0) { - + for (uint s = 0; s < (sizeof(services) / sizeof(*services)); s++) { if (GetServiceClass() & (1 << s)) { serviceClass << services[s]; @@ -23,7 +23,7 @@ DeviceClass::GetServiceClass(BString& serviceClass) serviceClass << ", "; } } - + } else serviceClass << "Unspecified"; @@ -53,55 +53,55 @@ DeviceClass::GetMinorDeviceClass(BString& minorClass) switch (major) { case 0: /* misc */ minorClass << " -"; - break; + break; case 1: /* computer */ switch(minor) { case 0: minorClass << "Uncategorized"; - break; + break; case 1: minorClass << "Desktop workstation"; - break; + break; case 2: minorClass << "Server"; - break; + break; case 3: minorClass << "Laptop"; - break; + break; case 4: minorClass << "Handheld"; - break; + break; case 5: minorClass << "Palm"; - break; + break; case 6: minorClass << "Wearable"; - break; + break; } - break; + break; case 2: /* phone */ switch(minor) { case 0: minorClass << "Uncategorized"; - break; + break; case 1: minorClass << "Cellular"; - break; + break; case 2: minorClass << "Cordless"; - break; + break; case 3: minorClass << "Smart phone"; - break; + break; case 4: minorClass << "Wired modem or voice gateway"; - break; + break; case 5: minorClass << "Common ISDN Access"; - break; + break; case 6: minorClass << "Sim Card Reader"; - break; + break; } break; case 3: /* lan access */ @@ -112,131 +112,133 @@ DeviceClass::GetMinorDeviceClass(BString& minorClass) switch(minor / 8) { case 0: minorClass << "Fully available"; - break; + break; case 1: minorClass << "1-17% utilized"; - break; + break; case 2: minorClass << "17-33% utilized"; - break; + break; case 3: minorClass << "33-50% utilized"; - break; + break; case 4: minorClass << "50-67% utilized"; - break; + break; case 5: minorClass << "67-83% utilized"; - break; + break; case 6: minorClass << "83-99% utilized"; - break; + break; case 7: minorClass << "No service available"; - break; + break; } - break; + break; case 4: /* audio/video */ switch(minor) { case 0: minorClass << "Uncategorized"; - break; + break; case 1: minorClass << "Device conforms to the Headset profile"; - break; + break; case 2: minorClass << "Hands-free"; - break; + break; /* 3 is reserved */ case 4: minorClass << "Microphone"; - break; + break; case 5: minorClass << "Loudspeaker"; - break; + break; case 6: minorClass << "Headphones"; - break; + break; case 7: minorClass << "Portable Audio"; - break; + break; case 8: minorClass << "Car Audio"; - break; + break; case 9: minorClass << "Set-top box"; - break; + break; case 10: minorClass << "HiFi Audio Device"; - break; + break; case 11: minorClass << "VCR"; - break; + break; case 12: minorClass << "Video Camera"; - break; + break; case 13: minorClass << "Camcorder"; - break; + break; case 14: minorClass << "Video Monitor"; - break; + break; case 15: minorClass << "Video Display and Loudspeaker"; - break; + break; case 16: minorClass << "Video Conferencing"; - break; + break; /* 17 is reserved */ case 18: minorClass << "Gaming/Toy"; - break; + break; } - break; - case 5: /* peripheral */ { + break; + case 5: /* peripheral */ + { switch(minor & 48) { case 16: minorClass << "Keyboard"; if (minor & 15) minorClass << "/"; - break; + break; case 32: minorClass << "Pointing device"; if (minor & 15) minorClass << "/"; - break; + break; case 48: minorClass << "Combo keyboard/pointing device"; if (minor & 15) minorClass << "/"; - break; + break; } switch(minor & 15) { case 0: - break; + break; case 1: minorClass << "Joystick"; - break; + break; case 2: minorClass << "Gamepad"; - break; + break; case 3: minorClass << "Remote control"; - break; + break; case 4: minorClass << "Sensing device"; - break; + break; case 5: minorClass << "Digitizer tablet"; - break; + break; case 6: minorClass << "Card reader"; - break; + break; default: minorClass << "(reserved)"; - break; + break; } + break; } case 6: /* imaging */ if (minor & 4) @@ -247,51 +249,51 @@ DeviceClass::GetMinorDeviceClass(BString& minorClass) minorClass << "Scanner"; if (minor & 32) minorClass << "Printer"; - break; + break; case 7: /* wearable */ switch(minor) { case 1: minorClass << "Wrist Watch"; - break; + break; case 2: minorClass << "Pager"; - break; + break; case 3: minorClass << "Jacket"; - break; + break; case 4: minorClass << "Helmet"; - break; + break; case 5: minorClass << "Glasses"; - break; + break; } - break; + break; case 8: /* toy */ switch(minor) { case 1: minorClass << "Robot"; - break; + break; case 2: minorClass << "Vehicle"; - break; + break; case 3: minorClass << "Doll / Action Figure"; - break; + break; case 4: minorClass << "Controller"; - break; + break; case 5: minorClass << "Game"; - break; + break; } - break; + break; case 63: /* uncategorised */ minorClass << ""; - break; + break; default: minorClass << "Unknown (reserved) minor device class"; - break; + break; } } @@ -307,7 +309,7 @@ DeviceClass::DumpDeviceClass(BString& string) string << " | "; string << "Minor Class: "; GetMinorDeviceClass(string); - string << "."; + string << "."; } } diff --git a/src/kits/bluetooth/DiscoveryAgent.cpp b/src/kits/bluetooth/DiscoveryAgent.cpp index f415b3cb8a..ece1202737 100644 --- a/src/kits/bluetooth/DiscoveryAgent.cpp +++ b/src/kits/bluetooth/DiscoveryAgent.cpp @@ -1,22 +1,20 @@ /* * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * * All rights reserved. Distributed under the terms of the MIT License. - * */ +#include #include #include -#include #include -#include +#include + #include #include #include #include - #include "KitSupport.h" namespace Bluetooth { @@ -25,7 +23,7 @@ namespace Bluetooth { RemoteDevicesList DiscoveryAgent::RetrieveDevices(int option) { - /* No inquiry process initiated */ + // No inquiry process initiated if (fLastUsedListener == NULL) return RemoteDevicesList(); @@ -64,7 +62,7 @@ DiscoveryAgent::StartInquiry(uint32 accessCode, DiscoveryListener* listener, big BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); BMessage reply; - request.AddInt32("hci_id", fLocalDevice->GetID()); + request.AddInt32("hci_id", fLocalDevice->ID()); startInquiryCommand = buildInquiry(accessCode, secs, BT_MAX_RESPONSES, &size); @@ -105,7 +103,7 @@ DiscoveryAgent::CancelInquiry(DiscoveryListener* listener) BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); BMessage reply; - request.AddInt32("hci_id", fLocalDevice->GetID()); + request.AddInt32("hci_id", fLocalDevice->ID()); cancelInquiryCommand = buildInquiryCancel(&size); request.AddData("raw command", B_ANY_TYPE, cancelInquiryCommand, size); @@ -121,12 +119,14 @@ DiscoveryAgent::CancelInquiry(DiscoveryListener* listener) return B_ERROR; } + void DiscoveryAgent::SetLocalDeviceOwner(LocalDevice* ld) { fLocalDevice = ld; } + DiscoveryAgent::DiscoveryAgent(LocalDevice* ld) { fLocalDevice = ld; @@ -136,8 +136,7 @@ DiscoveryAgent::DiscoveryAgent(LocalDevice* ld) DiscoveryAgent::~DiscoveryAgent() { - if (fMessenger) - delete fMessenger; + delete fMessenger; } diff --git a/src/kits/bluetooth/DiscoveryListener.cpp b/src/kits/bluetooth/DiscoveryListener.cpp index f53ae74116..c55b97d122 100644 --- a/src/kits/bluetooth/DiscoveryListener.cpp +++ b/src/kits/bluetooth/DiscoveryListener.cpp @@ -45,11 +45,12 @@ 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) { - fLocalDevice = ld; + fLocalDevice = ld; } @@ -63,26 +64,24 @@ DiscoveryListener::GetRemoteDevicesList(void) void DiscoveryListener::MessageReceived(BMessage* message) { - int8 status; + int8 status; - switch (message->what) - { - case BT_MSG_INQUIRY_DEVICE: - { + switch (message->what) { + case BT_MSG_INQUIRY_DEVICE: + { const struct inquiry_info* inquiryInfo; - ssize_t size; + 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 ) - { - // 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 )) { + 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)) { // update these values fRemoteDevicesList.ItemAt(index)->fPageRepetitionMode = inquiryInfo->pscan_rep_mode; @@ -90,60 +89,50 @@ DiscoveryListener::MessageReceived(BMessage* message) fRemoteDevicesList.ItemAt(index)->fScanMode = inquiryInfo->pscan_mode; fRemoteDevicesList.ItemAt(index)->fClockOffset = inquiryInfo->clock_offset; - duplicatedFound = true; - break; - } - } + duplicatedFound = true; + break; + } + } 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); + rd->SetLocalDeviceOwner(fLocalDevice); rd->fPageRepetitionMode = inquiryInfo->pscan_rep_mode; rd->fScanPeriodMode = inquiryInfo->pscan_period_mode; rd->fScanMode = inquiryInfo->pscan_mode; rd->fClockOffset = inquiryInfo->clock_offset; - DeviceDiscovered( rd, rd->GetDeviceClass()); - } - } - } - break; + DeviceDiscovered( rd, rd->GetDeviceClass()); + } + } + break; + } - case BT_MSG_INQUIRY_STARTED: - if (message->FindInt8("status", &status) == B_OK){ - fRemoteDevicesList.MakeEmpty(); - InquiryStarted(status); - } + case BT_MSG_INQUIRY_STARTED: + if (message->FindInt8("status", &status) == B_OK) { + fRemoteDevicesList.MakeEmpty(); + InquiryStarted(status); + } + break; - break; + case BT_MSG_INQUIRY_COMPLETED: + InquiryCompleted(BT_INQUIRY_COMPLETED); + break; - case BT_MSG_INQUIRY_COMPLETED: - - InquiryCompleted(BT_INQUIRY_COMPLETED); - - break; - case BT_MSG_INQUIRY_TERMINATED: /* inquiry was cancelled */ - - InquiryCompleted(BT_INQUIRY_TERMINATED); - - break; - case BT_MSG_INQUIRY_ERROR: - - InquiryCompleted(BT_INQUIRY_ERROR); - - break; - - default: - - BLooper::MessageReceived(message); - - break; - - } + case BT_MSG_INQUIRY_TERMINATED: /* inquiry was cancelled */ + InquiryCompleted(BT_INQUIRY_TERMINATED); + break; + + case BT_MSG_INQUIRY_ERROR: + InquiryCompleted(BT_INQUIRY_ERROR); + break; + default: + BLooper::MessageReceived(message); + break; + } } diff --git a/src/kits/bluetooth/LocalDevice.cpp b/src/kits/bluetooth/LocalDevice.cpp index 3c629fbca2..cdd561025f 100644 --- a/src/kits/bluetooth/LocalDevice.cpp +++ b/src/kits/bluetooth/LocalDevice.cpp @@ -9,15 +9,17 @@ #include #include -#include -#include #include #include +#include +#include #include #include #include +#include + #include "KitSupport.h" @@ -40,7 +42,7 @@ LocalDevice::RequestLocalDeviceID(BMessage* request) reply.FindInt32("hci_id", &hid) == B_OK ) { if (hid >= 0) - lDevice = new LocalDevice(hid); + lDevice = new (std::nothrow)LocalDevice(hid); } delete messenger; @@ -109,7 +111,7 @@ DiscoveryAgent* LocalDevice::GetDiscoveryAgent() { /* TODO: Study a singleton here */ - return new DiscoveryAgent(this); + return new (std::nothrow)DiscoveryAgent(this); } @@ -131,7 +133,7 @@ LocalDevice::GetProperty(const char* property, uint32* value) BMessage request(BT_MSG_GET_PROPERTY); BMessage reply; - request.AddInt32("hci_id", hid); + request.AddInt32("hci_id", fHid); request.AddString("property", property); if (fMessenger->SendMessage(&request, &reply) == B_OK) { @@ -166,7 +168,7 @@ LocalDevice::SetDiscoverable(int mode) int8 bt_status = BT_ERROR; - request.AddInt32("hci_id", hid); + request.AddInt32("hci_id", fHid); void* command = buildWriteScan(mode, &size); @@ -177,7 +179,8 @@ LocalDevice::SetDiscoverable(int mode) request.AddData("raw command", B_ANY_TYPE, command, size); request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); - request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_WRITE_SCAN_ENABLE)); + request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND, + OCF_WRITE_SCAN_ENABLE)); if (fMessenger->SendMessage(&request, &reply) == B_OK) { if (reply.FindInt8("status", &bt_status ) == B_OK ) { @@ -209,10 +212,11 @@ LocalDevice::GetBluetoothAddress() ssize_t ssize; /* ADD ID */ - request.AddInt32("hci_id", hid); + request.AddInt32("hci_id", fHid); request.AddData("raw command", B_ANY_TYPE, command, size); request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); - request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BD_ADDR)); + request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_INFORMATIONAL_PARAM, + OCF_READ_BD_ADDR)); if (fMessenger->SendMessage(&request, &reply) == B_OK) { if (reply.FindData("bdaddr", B_ANY_TYPE, 0, (const void**)&bdaddr, &ssize) == B_OK ) @@ -223,6 +227,13 @@ LocalDevice::GetBluetoothAddress() } +hci_id +LocalDevice::ID(void) const +{ + return fHid; +} + + BString LocalDevice::GetFriendlyName() { @@ -239,10 +250,11 @@ LocalDevice::GetFriendlyName() BMessage reply; - request.AddInt32("hci_id", hid); + request.AddInt32("hci_id", fHid); request.AddData("raw command", B_ANY_TYPE, command, size); request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); - request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_LOCAL_NAME)); + request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND, + OCF_READ_LOCAL_NAME)); if (fMessenger->SendMessage(&request, &reply) == B_OK && reply.FindString("friendlyname", &friendlyname) == B_OK){ @@ -273,13 +285,15 @@ LocalDevice::GetDeviceClass() const uint8* record; ssize_t ssize; - request.AddInt32("hci_id", hid); + request.AddInt32("hci_id", fHid); request.AddData("raw command", B_ANY_TYPE, command, size); request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); - request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_CLASS_OF_DEV)); + request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND, + OCF_READ_CLASS_OF_DEV)); - if (fMessenger->SendMessage(&request, &reply) == B_OK && - reply.FindData("devclass", B_ANY_TYPE, 0, (const void**)&record, &ssize) == B_OK) { + if (fMessenger->SendMessage(&request, &reply) == B_OK + && reply.FindData("devclass", B_ANY_TYPE, 0, (const void**)&record, + &ssize) == B_OK) { fDeviceClass.SetRecord(*record); } @@ -301,10 +315,11 @@ LocalDevice::ReadLocalVersion() BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); BMessage reply; - request.AddInt32("hci_id", hid); + request.AddInt32("hci_id", fHid); request.AddData("raw command", B_ANY_TYPE, localVersion.Data(), localVersion.Size()); request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); - request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_LOCAL_VERSION)); + request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_INFORMATIONAL_PARAM, + OCF_READ_LOCAL_VERSION)); if (fMessenger->SendMessage(&request, &reply) == B_OK) reply.FindInt8("status", &bt_status); @@ -324,10 +339,11 @@ LocalDevice::ReadBufferSize() BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); BMessage reply; - request.AddInt32("hci_id", hid); + request.AddInt32("hci_id", fHid); request.AddData("raw command", B_ANY_TYPE, BufferSize.Data(), BufferSize.Size()); request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); - request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BUFFER_SIZE)); + request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_INFORMATIONAL_PARAM, + OCF_READ_BUFFER_SIZE)); if (fMessenger->SendMessage(&request, &reply) == B_OK) reply.FindInt8("status", &bt_status); @@ -347,16 +363,17 @@ LocalDevice::Reset() BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); BMessage reply; - request.AddInt32("hci_id", hid); + request.AddInt32("hci_id", fHid); request.AddData("raw command", B_ANY_TYPE, Reset.Data(), Reset.Size()); request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); - request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_RESET)); - + request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND, + OCF_RESET)); + if (fMessenger->SendMessage(&request, &reply) == B_OK) reply.FindInt8("status", &bt_status); return bt_status; - + } /* @@ -372,7 +389,7 @@ LocalDevice::updateRecord(ServiceRecord srvRecord) { */ -LocalDevice::LocalDevice(hci_id hid) : hid(hid) +LocalDevice::LocalDevice(hci_id hid) : fHid(hid) { fMessenger = _RetrieveBluetoothMessenger(); ReadLocalVersion(); @@ -384,14 +401,15 @@ LocalDevice::LocalDevice(hci_id hid) : hid(hid) // Uncomment this out if your Broadcom dongle is not working properly // Reset(); // Perform a reset to Broadcom buggyland - + //#define BT_WRITE_BDADDR_FOR_BCM2035 #ifdef BT_WRITE_BDADDR_FOR_BCM2035 - // try the bcm stuff + // try write bdaddr to a bcm2035 -> will be moved to an addon int8 bt_status = BT_ERROR; - BluetoothCommand writeAddress(OGF_VENDOR_CMD, OCF_WRITE_BCM2035_BDADDR); + BluetoothCommand + writeAddress(OGF_VENDOR_CMD, OCF_WRITE_BCM2035_BDADDR); BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); BMessage reply; @@ -402,10 +420,11 @@ LocalDevice::LocalDevice(hci_id hid) : hid(hid) writeAddress->bdaddr.b[4] = 0x03; writeAddress->bdaddr.b[5] = 0x00; - request.AddInt32("hci_id", hid); + request.AddInt32("hci_id", fHid); request.AddData("raw command", B_ANY_TYPE, writeAddress.Data(), writeAddress.Size()); request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); - request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_VENDOR_CMD, OCF_WRITE_BCM2035_BDADDR)); + request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_VENDOR_CMD, + OCF_WRITE_BCM2035_BDADDR)); if (fMessenger->SendMessage(&request, &reply) == B_OK) reply.FindInt8("status", &bt_status); @@ -418,8 +437,7 @@ LocalDevice::LocalDevice(hci_id hid) : hid(hid) LocalDevice::~LocalDevice() { - if (fMessenger) - delete fMessenger; + delete fMessenger; } diff --git a/src/kits/bluetooth/RemoteDevice.cpp b/src/kits/bluetooth/RemoteDevice.cpp index e9e6dbf5f6..b5c05d9d10 100644 --- a/src/kits/bluetooth/RemoteDevice.cpp +++ b/src/kits/bluetooth/RemoteDevice.cpp @@ -35,47 +35,45 @@ RemoteDevice::IsTrustedDevice(void) BString RemoteDevice::GetFriendlyName(bool alwaysAsk) { - if (!alwaysAsk) { // Check if the name is already retrieved // TODO: Check if It is known from a KnownDevicesList return BString("Not implemented"); } - + if (fDiscovererLocalDevice == NULL) return BString("#NoOwnerError#Not Valid name"); - + if (fMessenger == NULL) return BString("#ServerNotReady#Not Valid name"); - - void* remoteNameCommand = NULL; + + void* remoteNameCommand = NULL; size_t size; - + // Issue inquiry command BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); BMessage reply; - - request.AddInt32("hci_id", fDiscovererLocalDevice->GetID()); - + + request.AddInt32("hci_id", fDiscovererLocalDevice->ID()); + // Fill the request - remoteNameCommand = buildRemoteNameRequest(fBdaddr, fPageRepetitionMode, fClockOffset, &size); // Fill correctily - + remoteNameCommand = buildRemoteNameRequest(fBdaddr, fPageRepetitionMode, fClockOffset, &size); + request.AddData("raw command", B_ANY_TYPE, remoteNameCommand, size); - + request.AddInt16("eventExpected", HCI_EVENT_CMD_STATUS); request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST)); - + request.AddInt16("eventExpected", HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE); - - - if (fMessenger->SendMessage(&request, &reply) == B_OK) - { + + + if (fMessenger->SendMessage(&request, &reply) == B_OK) { BString name; int8 status; - + if ((reply.FindInt8("status", &status) == B_OK) && (status == BT_OK)) { - if ((reply.FindString("friendlyname", &name) == B_OK ) ) { + if ((reply.FindString("friendlyname", &name) == B_OK )) { return name; } else { return BString(""); // should not happen @@ -113,8 +111,10 @@ RemoteDevice::Equals(RemoteDevice* obj) return bdaddrUtils::Compare(&fBdaddr, &ba); } + // static RemoteDevice* GetRemoteDevice(Connection conn); + bool RemoteDevice::Authenticate() { @@ -142,12 +142,14 @@ RemoteDevice::IsEncrypted() return true; } + LocalDevice* RemoteDevice::GetLocalDeviceOwner() { return fDiscovererLocalDevice; } + /* Private */ void RemoteDevice::SetLocalDeviceOwner(LocalDevice* ld) @@ -175,8 +177,7 @@ RemoteDevice::RemoteDevice(const BString& address) RemoteDevice::~RemoteDevice() { - if (fMessenger) - delete fMessenger; + delete fMessenger; } diff --git a/src/servers/bluetooth/LocalDeviceImpl.cpp b/src/servers/bluetooth/LocalDeviceImpl.cpp index 9b2fa96a72..69aee2bf2a 100644 --- a/src/servers/bluetooth/LocalDeviceImpl.cpp +++ b/src/servers/bluetooth/LocalDeviceImpl.cpp @@ -22,6 +22,7 @@ #include #include +#include #if 0 @@ -33,10 +34,10 @@ LocalDeviceImpl* LocalDeviceImpl::CreateControllerAccessor(BPath* path) { - HCIDelegate* hd = new HCIControllerAccessor(path); + HCIDelegate* hd = new (std::nothrow)HCIControllerAccessor(path); if (hd != NULL) - return new LocalDeviceImpl(hd); + return new (std::nothrow)LocalDeviceImpl(hd); else return NULL; } @@ -45,10 +46,10 @@ LocalDeviceImpl::CreateControllerAccessor(BPath* path) LocalDeviceImpl* LocalDeviceImpl::CreateTransportAccessor(BPath* path) { - HCIDelegate* hd = new HCITransportAccessor(path); + HCIDelegate* hd = new (std::nothrow)HCITransportAccessor(path); if (hd != NULL) - return new LocalDeviceImpl(hd); + return new (std::nothrow)LocalDeviceImpl(hd); else return NULL; }