1 /* 2 * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com 3 * 4 * All rights reserved. Distributed under the terms of the MIT License. 5 * 6 */ 7 8 9 #include <bluetooth/DiscoveryAgent.h> 10 #include <bluetooth/DiscoveryListener.h> 11 #include <bluetooth/bdaddrUtils.h> 12 #include <bluetooth/LocalDevice.h> 13 14 #include <bluetooth/RemoteDevice.h> 15 16 #include <bluetoothserver_p.h> 17 #include <bluetooth/HCI/btHCI_command.h> 18 #include <bluetooth/HCI/btHCI_event.h> 19 #include <CommandManager.h> 20 21 #include "KitSupport.h" 22 23 24 25 namespace Bluetooth { 26 27 28 bool 29 RemoteDevice::IsTrustedDevice(void) 30 { 31 return true; 32 } 33 34 BString 35 RemoteDevice::GetFriendlyName(bool alwaysAsk) 36 { 37 38 if (!alwaysAsk) { 39 // Check if the name is already retrieved 40 return BString("Not implemented"); 41 42 // TODO: Check if It is known from a KnownDevicesList 43 } 44 45 if (fDiscovererLocalDevice == NULL) 46 return BString("#NoOwnerError#Not Valid name"); 47 48 BMessenger* btsm = NULL; 49 size_t size; 50 51 if ((btsm = _RetrieveBluetoothMessenger()) == NULL) 52 return BString("#ServerNotReady#Not Valid name"); 53 54 void* remoteNameCommand = NULL; 55 56 /* Issue inquiry command */ 57 BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); 58 BMessage reply; 59 60 request.AddInt32("hci_id", fDiscovererLocalDevice->GetID()); 61 62 // Fill the request 63 remoteNameCommand = buildRemoteNameRequest(fBdaddr, fPageRepetitionMode, fClockOffset, &size); // Fill correctily 64 65 request.AddData("raw command", B_ANY_TYPE, remoteNameCommand, size); 66 67 request.AddInt16("eventExpected", HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE); 68 //request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST)); 69 70 if (btsm->SendMessage(&request, &reply) == B_OK) 71 { 72 BString name; 73 int8 status; 74 75 if (reply.FindInt8("status", &status) == B_OK && 76 reply.FindString("friendlyname", &name) == B_OK ) { 77 return name; 78 } 79 } 80 81 return BString("#NotCompletedRequestr#Not Valid name"); 82 } 83 84 85 bdaddr_t 86 RemoteDevice::GetBluetoothAddress() 87 { 88 return fBdaddr; 89 } 90 91 92 bool 93 RemoteDevice::Equals(RemoteDevice* obj) 94 { 95 bdaddr_t ba = obj->GetBluetoothAddress(); 96 97 return bdaddrUtils::Compare(&fBdaddr, &ba); 98 } 99 100 // static RemoteDevice* GetRemoteDevice(Connection conn); 101 102 bool 103 RemoteDevice::Authenticate() 104 { 105 return true; 106 } 107 108 109 // bool Authorize(Connection conn); 110 // bool Encrypt(Connection conn, bool on); 111 112 113 bool 114 RemoteDevice::IsAuthenticated() 115 { 116 return true; 117 } 118 119 120 // bool IsAuthorized(Connection conn); 121 122 123 bool 124 RemoteDevice::IsEncrypted() 125 { 126 return true; 127 } 128 129 /* Private */ 130 void 131 RemoteDevice::SetLocalDeviceOwner(LocalDevice* ld) 132 { 133 fDiscovererLocalDevice = ld; 134 } 135 136 /* Constructor */ 137 RemoteDevice::RemoteDevice(bdaddr_t address) 138 { 139 fBdaddr = address; 140 } 141 142 RemoteDevice::RemoteDevice(BString address) 143 { 144 /* TODO */ 145 146 } 147 148 }