diff --git a/headers/os/bluetooth/DeviceClass.h b/headers/os/bluetooth/DeviceClass.h index b2df2e8eb3..abb764c471 100644 --- a/headers/os/bluetooth/DeviceClass.h +++ b/headers/os/bluetooth/DeviceClass.h @@ -10,8 +10,7 @@ namespace Bluetooth { -#define UNKNOWN_CLASS_OF_DEVICE 0x00 - +#define UNKNOWN_CLASS_OF_DEVICE 0x000000 class DeviceClass { @@ -26,45 +25,53 @@ public: } - DeviceClass(uint32 record) + DeviceClass(uint8 major, uint8 minor, uint16 service) { - SetRecord(record); + SetRecord(major, minor, service); } DeviceClass(void) { - this->record = UNKNOWN_CLASS_OF_DEVICE; + fRecord = UNKNOWN_CLASS_OF_DEVICE; } void SetRecord(uint8 record[3]) { - this->record = record[0]|record[1]<<8|record[2]<<16; + fRecord = record[0]|record[1]<<8|record[2]<<16; } - void SetRecord(uint32 record) + void SetRecord(uint8 major, uint8 minor, uint16 service) { - this->record = record; + fRecord = (minor & 0x3F) << 2; + fRecord |= (major & 0x1F) << 8; + fRecord |= (service & 0x7FF) << 13; } - uint GetServiceClass() + + uint16 ServiceClass() { - return (record & 0x00FFE000) >> 13; + return (fRecord & 0x00FFE000) >> 13; } - uint GetMajorDeviceClass() + uint8 MajorDeviceClass() { - return (record & 0x00001F00) >> 8; + return (fRecord & 0x00001F00) >> 8; } - uint GetMinorDeviceClass() + uint8 MinorDeviceClass() { - return (record & 0x000000FF) >> 2; + return (fRecord & 0x000000FF) >> 2; + } + + uint32 Record() + { + return fRecord; } bool IsUnknownDeviceClass() { - return (record == UNKNOWN_CLASS_OF_DEVICE); + return (fRecord == UNKNOWN_CLASS_OF_DEVICE); } void GetServiceClass(BString&); @@ -76,7 +83,7 @@ public: void Draw(BView* view, const BPoint& point); private: - uint32 record; + uint32 fRecord; }; diff --git a/headers/os/bluetooth/LocalDevice.h b/headers/os/bluetooth/LocalDevice.h index 31ae2f4035..a3886afd68 100644 --- a/headers/os/bluetooth/LocalDevice.h +++ b/headers/os/bluetooth/LocalDevice.h @@ -34,6 +34,8 @@ public: DiscoveryAgent* GetDiscoveryAgent(); BString GetFriendlyName(); DeviceClass GetDeviceClass(); + status_t SetDeviceClass(DeviceClass deviceClass); + /* Possible throwing */ status_t SetDiscoverable(int mode); diff --git a/src/kits/bluetooth/DeviceClass.cpp b/src/kits/bluetooth/DeviceClass.cpp index da1d2cae8f..21123356a3 100644 --- a/src/kits/bluetooth/DeviceClass.cpp +++ b/src/kits/bluetooth/DeviceClass.cpp @@ -14,18 +14,23 @@ DeviceClass::GetServiceClass(BString& serviceClass) "Rendering", "Capturing", "Object Transfer", "Audio", "Telephony", "Information" }; - if (GetServiceClass() != 0) { + if (ServiceClass() != 0) { + bool first = true; for (uint s = 0; s < (sizeof(services) / sizeof(*services)); s++) { - if (GetServiceClass() & (1 << s)) { - serviceClass << services[s]; - if (s != 0) - serviceClass << ", "; + if (ServiceClass() & (1 << s)) { + if (first) { + first = false; + serviceClass << services[s]; + } else { + serviceClass << ", " << services[s]; + } + } } } else - serviceClass << "Unspecified"; + serviceClass << "Unspecified"; } @@ -36,10 +41,10 @@ DeviceClass::GetMajorDeviceClass(BString& majorClass) static const char *major_devices[] = { "Miscellaneous", "Computer", "Phone", "LAN Access", "Audio/Video", "Peripheral", "Imaging", "Uncategorized" }; - if (GetMajorDeviceClass() >= sizeof(major_devices) / sizeof(*major_devices)) + if (MajorDeviceClass() >= sizeof(major_devices) / sizeof(*major_devices)) majorClass << "Invalid Device Class!\n"; else - majorClass << major_devices[GetMajorDeviceClass()]; + majorClass << major_devices[MajorDeviceClass()]; } @@ -47,8 +52,8 @@ DeviceClass::GetMajorDeviceClass(BString& majorClass) void DeviceClass::GetMinorDeviceClass(BString& minorClass) { - uint major = GetMajorDeviceClass(); - uint minor = GetMinorDeviceClass(); + uint major = MajorDeviceClass(); + uint minor = MinorDeviceClass(); switch (major) { case 0: /* misc */ @@ -327,7 +332,7 @@ DeviceClass::Draw(BView* view, const BPoint& point) view->SetHighColor(kWhite); - switch (GetMajorDeviceClass()) { + switch (MajorDeviceClass()) { case 2: // phone view->StrokeRoundRect(BRect(point.x + IconInsets + uint(PixelsForIcon/4), diff --git a/src/kits/bluetooth/LocalDevice.cpp b/src/kits/bluetooth/LocalDevice.cpp index cdd561025f..0c74dbed68 100644 --- a/src/kits/bluetooth/LocalDevice.cpp +++ b/src/kits/bluetooth/LocalDevice.cpp @@ -211,7 +211,6 @@ LocalDevice::GetBluetoothAddress() BMessage reply; ssize_t ssize; - /* ADD ID */ request.AddInt32("hci_id", fHid); request.AddData("raw command", B_ANY_TYPE, command, size); request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); @@ -270,7 +269,7 @@ DeviceClass LocalDevice::GetDeviceClass() { - if (fDeviceClass.IsUnknownDeviceClass()) { +// if (fDeviceClass.IsUnknownDeviceClass()) { if (fMessenger == NULL) return fDeviceClass; @@ -282,7 +281,7 @@ LocalDevice::GetDeviceClass() BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); BMessage reply; - const uint8* record; + const uint8* bufferRecord; ssize_t ssize; request.AddInt32("hci_id", fHid); @@ -292,26 +291,57 @@ LocalDevice::GetDeviceClass() OCF_READ_CLASS_OF_DEV)); if (fMessenger->SendMessage(&request, &reply) == B_OK - && reply.FindData("devclass", B_ANY_TYPE, 0, (const void**)&record, + && reply.FindData("devclass", B_ANY_TYPE, 0, (const void**)&bufferRecord, &ssize) == B_OK) { - - fDeviceClass.SetRecord(*record); + uint8 record[3] = { bufferRecord[0], bufferRecord[1], bufferRecord[2] }; + fDeviceClass.SetRecord(record); } - } +// } return fDeviceClass; } +status_t +LocalDevice::SetDeviceClass(DeviceClass deviceClass) +{ + int8 bt_status = BT_ERROR; + + if (fMessenger == NULL) + return bt_status; + + BluetoothCommand + setDeviceClass(OGF_CONTROL_BASEBAND, OCF_WRITE_CLASS_OF_DEV); + + setDeviceClass->dev_class[0] = deviceClass.Record() & 0xFF; + setDeviceClass->dev_class[1] = (deviceClass.Record() & 0xFF00) >> 8; + setDeviceClass->dev_class[2] = (deviceClass.Record() & 0xFF0000) >> 16; + + BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); + BMessage reply; + + request.AddInt32("hci_id", fHid); + request.AddData("raw command", B_ANY_TYPE, setDeviceClass.Data(), setDeviceClass.Size()); + request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); + request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND, + OCF_WRITE_CLASS_OF_DEV)); + + if (fMessenger->SendMessage(&request, &reply) == B_OK) + reply.FindInt8("status", &bt_status); + + return bt_status; + +} + + status_t LocalDevice::ReadLocalVersion() { - int8 bt_status = BT_ERROR; + int8 bt_status = BT_ERROR; BluetoothCommand<> localVersion(OGF_INFORMATIONAL_PARAM,OCF_READ_LOCAL_VERSION); - BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); BMessage reply; diff --git a/src/preferences/bluetooth/BluetoothSettingsView.cpp b/src/preferences/bluetooth/BluetoothSettingsView.cpp index a2feb63697..cae947c97c 100644 --- a/src/preferences/bluetooth/BluetoothSettingsView.cpp +++ b/src/preferences/bluetooth/BluetoothSettingsView.cpp @@ -25,7 +25,12 @@ #include "BluetoothWindow.h" static const int32 kMsgSetAntialiasing = 'anti'; -static const int32 kMsgSetHinting = 'hint'; +static const int32 kMsgSetDeviceClassDesktop = 'sDCd'; +static const int32 kMsgSetDeviceClassServer = 'sDCs'; +static const int32 kMsgSetDeviceClassLaptop = 'sDCl'; +static const int32 kMsgSetDeviceClassNetbook = 'sDCn'; +static const int32 kMsgSetDeviceClassSmartPhone = 'sDCp'; + static const int32 kMsgSetAverageWeight = 'afEa'; static const int32 kMsgLocalSwitched = 'lDsW'; @@ -34,8 +39,10 @@ static const char* kTrustedLabel = "Only from Trusted devices"; static const char* kAlwaysLabel = "Always ask"; static const char* kDesktopLabel = "Desktop"; +static const char* kServerLabel = "Server"; static const char* kLaptopLabel = "Laptop"; -static const char* kPhoneLabel = "Haiku Phone"; +static const char* kNetBookLabel = "NetBook"; +static const char* kPhoneLabel = "Smart Phone"; // #pragma mark - @@ -119,6 +126,9 @@ BluetoothSettingsView::AttachedToWindow() void BluetoothSettingsView::MessageReceived(BMessage *msg) { + + DeviceClass devClass; + switch (msg->what) { case kMsgLocalSwitched: { @@ -131,6 +141,42 @@ BluetoothSettingsView::MessageReceived(BMessage *msg) } } break; + + case kMsgSetDeviceClassDesktop: + { + devClass.SetRecord(1, 1, 0x72); + ActiveLocalDevice->SetDeviceClass(devClass); + break; + } + + case kMsgSetDeviceClassServer: + { + devClass.SetRecord(1, 2, 0x72); + ActiveLocalDevice->SetDeviceClass(devClass); + break; + } + + case kMsgSetDeviceClassLaptop: + { + devClass.SetRecord(1, 3, 0x72); + ActiveLocalDevice->SetDeviceClass(devClass); + break; + } + + case kMsgSetDeviceClassNetbook: + { + devClass.SetRecord(1, 4, 0x72); + ActiveLocalDevice->SetDeviceClass(devClass); + break; + } + + case kMsgSetDeviceClassSmartPhone: + { + devClass.SetRecord(2, 3, 0x72); + ActiveLocalDevice->SetDeviceClass(devClass); + break; + } + case kMsgRefresh: _BuildLocalDevicesMenu(); fLocalDevicesMenu->SetTargetForItems(this); @@ -169,25 +215,31 @@ BluetoothSettingsView::_BuildConnectionPolicy() void BluetoothSettingsView::_BuildHintingMenu() -{ +{ + fHintingMenu = new BPopUpMenu("Identify us as..."); - - BMessage* message = new BMessage(kMsgSetHinting); - message->AddBool("hinting", false); - + BMessage* message; + + message = new BMessage(kMsgSetDeviceClassDesktop); BMenuItem* item = new BMenuItem(kDesktopLabel, message); - fHintingMenu->AddItem(item); - message = new BMessage(kMsgSetAverageWeight); - message->AddBool("hinting", true); - - item = new BMenuItem(kLaptopLabel, message); - + message = new BMessage(kMsgSetDeviceClassServer); + item = new BMenuItem(kServerLabel, message); + fHintingMenu->AddItem(item); + + message = new BMessage(kMsgSetDeviceClassLaptop); + item = new BMenuItem(kLaptopLabel, message); + fHintingMenu->AddItem(item); + + message = new BMessage(kMsgSetDeviceClassNetbook); + item = new BMenuItem(kNetBookLabel, message); + fHintingMenu->AddItem(item); + + message = new BMessage(kMsgSetDeviceClassSmartPhone); + item = new BMenuItem(kPhoneLabel, message); fHintingMenu->AddItem(item); - BMenuItem* item2 = new BMenuItem(kPhoneLabel, NULL); - fHintingMenu->AddItem(item2); }