void LocalDeviceImpl::LinkKeyRequested(struct hci_ev_link_key_req* keyRequested, BMessage* request) { TRACE_BT("LocalDeviceImpl: %s: Address %s\n", __FUNCTION__, bdaddrUtils::ToString(keyRequested->bdaddr).String()); // TODO: // Here we are suposed to check the BDADDR received, look into the server // (RemoteDevice Database) if we have any pas link key interchanged with // the given address if we have we are to accept it will "Link key Request // Reply". As we dont not have such database yet, we will always deny it // forcing the remote device to start a pairing. BluetoothCommand<typed_command(hci_cp_link_key_neg_reply)> linkKeyNegativeReply(OGF_LINK_CONTROL, OCF_LINK_KEY_NEG_REPLY); bdaddrUtils::Copy(linkKeyNegativeReply->bdaddr, keyRequested->bdaddr); if ((fHCIDelegate)->IssueCommand(linkKeyNegativeReply.Data(), linkKeyNegativeReply.Size()) == B_ERROR) { TRACE_BT("LocalDeviceImpl: Command issued error for reply %s\n", __FUNCTION__); } else { TRACE_BT("LocalDeviceImpl: Command issued in reply of %s\n", __FUNCTION__); } if (request != NULL) ClearWantedEvent(request, HCI_EVENT_LINK_KEY_REQ); }
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::SetFriendlyName(BString& name) { int8 btStatus = BT_ERROR; if (fMessenger == NULL) return btStatus; BluetoothCommand<typed_command(hci_write_local_name)> writeName(OGF_CONTROL_BASEBAND, OCF_WRITE_LOCAL_NAME); strcpy(writeName->local_name, name.String()); BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); BMessage reply; request.AddInt32("hci_id", fHid); request.AddData("raw command", B_ANY_TYPE, writeName.Data(), writeName.Size()); request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_WRITE_LOCAL_NAME)); if (fMessenger->SendMessage(&request, &reply) == B_OK) reply.FindInt8("status", &btStatus); return btStatus; }
LocalDevice::LocalDevice(hci_id hid) : BluetoothDevice(), fHid(hid) { fMessenger = _RetrieveBluetoothMessenger(); _ReadBufferSize(); _ReadLocalFeatures(); _ReadLocalVersion(); _ReadTimeouts(); _ReadLinkKeys(); // Uncomment this if you want your device to have a nicer default name // BString name("HaikuBluetooth"); // SetFriendlyName(name); uint32 value; // HARDCODE -> move this to addons if (GetProperty("manufacturer", &value) == B_OK && value == 15) { // Uncomment this out if your Broadcom dongle is not working properly // Reset(); // Perform a reset to Broadcom buggyland // Uncomment this out if your Broadcom dongle has a null bdaddr //#define BT_WRITE_BDADDR_FOR_BCM2035 #ifdef BT_WRITE_BDADDR_FOR_BCM2035 #warning Writting broadcom bdaddr @ init. // try write bdaddr to a bcm2035 -> will be moved to an addon int8 bt_status = BT_ERROR; BluetoothCommand<typed_command(hci_write_bcm2035_bdaddr)> writeAddress(OGF_VENDOR_CMD, OCF_WRITE_BCM2035_BDADDR); BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); BMessage reply; writeAddress->bdaddr.b[0] = 0x3C; writeAddress->bdaddr.b[1] = 0x19; writeAddress->bdaddr.b[2] = 0x30; writeAddress->bdaddr.b[3] = 0xC9; writeAddress->bdaddr.b[4] = 0x03; writeAddress->bdaddr.b[5] = 0x00; 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)); if (fMessenger->SendMessage(&request, &reply) == B_OK) reply.FindInt8("status", &bt_status); #endif } }