- Add method in LocalDevice class to write its class to the dongle
- Rework and style the DeviceClass class - Implement option "Identify host as..." in preferences with mentioned method, this should allow us to be visible to more RemoteDevices git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31502 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@ public:
|
||||
DiscoveryAgent* GetDiscoveryAgent();
|
||||
BString GetFriendlyName();
|
||||
DeviceClass GetDeviceClass();
|
||||
status_t SetDeviceClass(DeviceClass deviceClass);
|
||||
|
||||
/* Possible throwing */
|
||||
status_t SetDiscoverable(int mode);
|
||||
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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<typed_command(hci_write_dev_class)>
|
||||
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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user