/* * Copyright 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 "KitSupport.h" namespace Bluetooth { bool RemoteDevice::IsTrustedDevice(void) { return true; } BString RemoteDevice::GetFriendlyName(bool alwaysAsk) { if (!alwaysAsk) { // Check if the name is already retrieved return BString("Not implemented"); // TODO: Check if It is known from a KnownDevicesList } if (fDiscovererLocalDevice == NULL) return BString("#NoOwnerError#Not Valid name"); BMessenger* btsm = NULL; size_t size; if ((btsm = _RetrieveBluetoothMessenger()) == NULL) return BString("#ServerNotReady#Not Valid name"); void* remoteNameCommand = NULL; /* Issue inquiry command */ BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); BMessage reply; request.AddInt32("hci_id", fDiscovererLocalDevice->GetID()); // Fill the request remoteNameCommand = buildRemoteNameRequest(fBdaddr, fPageRepetitionMode, fClockOffset, &size); // Fill correctily request.AddData("raw command", B_ANY_TYPE, remoteNameCommand, size); request.AddInt16("eventExpected", HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE); //request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST)); if (btsm->SendMessage(&request, &reply) == B_OK) { BString name; int8 status; if (reply.FindInt8("status", &status) == B_OK && reply.FindString("friendlyname", &name) == B_OK ) { return name; } } return BString("#NotCompletedRequestr#Not Valid name"); } bdaddr_t RemoteDevice::GetBluetoothAddress() { return fBdaddr; } bool RemoteDevice::Equals(RemoteDevice* obj) { bdaddr_t ba = obj->GetBluetoothAddress(); return bdaddrUtils::Compare(&fBdaddr, &ba); } // static RemoteDevice* GetRemoteDevice(Connection conn); bool RemoteDevice::Authenticate() { return true; } // bool Authorize(Connection conn); // bool Encrypt(Connection conn, bool on); bool RemoteDevice::IsAuthenticated() { return true; } // bool IsAuthorized(Connection conn); bool RemoteDevice::IsEncrypted() { return true; } /* Private */ void RemoteDevice::SetLocalDeviceOwner(LocalDevice* ld) { fDiscovererLocalDevice = ld; } /* Constructor */ RemoteDevice::RemoteDevice(bdaddr_t address) { fBdaddr = address; } RemoteDevice::RemoteDevice(BString address) { /* TODO */ } }