130f1d1f3SOliver Ruiz Dorantes /* 2e5da0ec5SOliver Ruiz Dorantes * Copyright 2007-2009 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com 3e5da0ec5SOliver Ruiz Dorantes * Copyright 2008 Mika Lindqvist, monni1995_at_gmail.com 430f1d1f3SOliver Ruiz Dorantes * All rights reserved. Distributed under the terms of the MIT License. 530f1d1f3SOliver Ruiz Dorantes * 630f1d1f3SOliver Ruiz Dorantes */ 730f1d1f3SOliver Ruiz Dorantes 830f1d1f3SOliver Ruiz Dorantes #include <stdio.h> 930f1d1f3SOliver Ruiz Dorantes #include <fcntl.h> 1030f1d1f3SOliver Ruiz Dorantes #include <unistd.h> 1130f1d1f3SOliver Ruiz Dorantes 1230f1d1f3SOliver Ruiz Dorantes #include <Entry.h> 1330f1d1f3SOliver Ruiz Dorantes #include <Directory.h> 14e5da0ec5SOliver Ruiz Dorantes #include <Message.h> 15e5da0ec5SOliver Ruiz Dorantes #include <Path.h> 1630f1d1f3SOliver Ruiz Dorantes #include <Roster.h> 17e5da0ec5SOliver Ruiz Dorantes #include <String.h> 1830f1d1f3SOliver Ruiz Dorantes 1930f1d1f3SOliver Ruiz Dorantes #include <TypeConstants.h> 2030f1d1f3SOliver Ruiz Dorantes #include <syslog.h> 2130f1d1f3SOliver Ruiz Dorantes 2230f1d1f3SOliver Ruiz Dorantes #include <bluetoothserver_p.h> 2330f1d1f3SOliver Ruiz Dorantes #include <bluetooth/HCI/btHCI_command.h> 2430f1d1f3SOliver Ruiz Dorantes #include <bluetooth/bluetooth_util.h> 2530f1d1f3SOliver Ruiz Dorantes 2630f1d1f3SOliver Ruiz Dorantes #include "LocalDeviceImpl.h" 2730f1d1f3SOliver Ruiz Dorantes #include "BluetoothServer.h" 2830f1d1f3SOliver Ruiz Dorantes #include "Output.h" 2930f1d1f3SOliver Ruiz Dorantes 3030f1d1f3SOliver Ruiz Dorantes 3130f1d1f3SOliver Ruiz Dorantes BluetoothServer::BluetoothServer() : BApplication(BLUETOOTH_SIGNATURE) 3230f1d1f3SOliver Ruiz Dorantes { 3330f1d1f3SOliver Ruiz Dorantes Output::Instance()->Run(); 3430f1d1f3SOliver Ruiz Dorantes Output::Instance()->SetTitle("Bluetooth message gathering"); 3530f1d1f3SOliver Ruiz Dorantes 3630f1d1f3SOliver Ruiz Dorantes Output::Instance()->AddTab("General", BLACKBOARD_GENERAL); 3730f1d1f3SOliver Ruiz Dorantes Output::Instance()->AddTab("Device Manager", BLACKBOARD_DEVICEMANAGER); 3830f1d1f3SOliver Ruiz Dorantes Output::Instance()->AddTab("Kit", BLACKBOARD_KIT); 3930f1d1f3SOliver Ruiz Dorantes 4030f1d1f3SOliver Ruiz Dorantes ShowWindow(Output::Instance()); 4130f1d1f3SOliver Ruiz Dorantes 4230f1d1f3SOliver Ruiz Dorantes fDeviceManager = new DeviceManager(); 4330f1d1f3SOliver Ruiz Dorantes fLocalDevicesList.MakeEmpty(); 4430f1d1f3SOliver Ruiz Dorantes 45d23283c4SOliver Ruiz Dorantes // TODO: Some events should be handled faster than in KL... 46e5da0ec5SOliver Ruiz Dorantes fEventListener = spawn_thread(notification_Thread, "BT port listener" , 47e5da0ec5SOliver Ruiz Dorantes B_URGENT_DISPLAY_PRIORITY , this); 4830f1d1f3SOliver Ruiz Dorantes 4930f1d1f3SOliver Ruiz Dorantes } 5030f1d1f3SOliver Ruiz Dorantes 5130f1d1f3SOliver Ruiz Dorantes bool BluetoothServer::QuitRequested(void) 5230f1d1f3SOliver Ruiz Dorantes { 5330f1d1f3SOliver Ruiz Dorantes // Finish quitting 5430f1d1f3SOliver Ruiz Dorantes Output::Instance()->Lock(); 5530f1d1f3SOliver Ruiz Dorantes Output::Instance()->Quit(); 5630f1d1f3SOliver Ruiz Dorantes 57e5da0ec5SOliver Ruiz Dorantes LocalDeviceImpl* ldi = NULL; 58e5da0ec5SOliver Ruiz Dorantes while ((ldi = (LocalDeviceImpl *)fLocalDevicesList.RemoveItem((int32)0)) 59e5da0ec5SOliver Ruiz Dorantes != NULL) 60e5da0ec5SOliver Ruiz Dorantes delete ldi; 6130f1d1f3SOliver Ruiz Dorantes 6230f1d1f3SOliver Ruiz Dorantes printf("Accepting quitting of the application\n"); 6330f1d1f3SOliver Ruiz Dorantes return BApplication::QuitRequested(); 6430f1d1f3SOliver Ruiz Dorantes } 6530f1d1f3SOliver Ruiz Dorantes 66e5da0ec5SOliver Ruiz Dorantes 6730f1d1f3SOliver Ruiz Dorantes void BluetoothServer::ArgvReceived(int32 argc, char **argv) 6830f1d1f3SOliver Ruiz Dorantes { 6930f1d1f3SOliver Ruiz Dorantes if (argc>1) { 7030f1d1f3SOliver Ruiz Dorantes if (strcmp(argv[1], "--finish") == 0) 7130f1d1f3SOliver Ruiz Dorantes PostMessage(B_QUIT_REQUESTED); 7230f1d1f3SOliver Ruiz Dorantes } 7330f1d1f3SOliver Ruiz Dorantes 7430f1d1f3SOliver Ruiz Dorantes } 7530f1d1f3SOliver Ruiz Dorantes 7630f1d1f3SOliver Ruiz Dorantes 77e5da0ec5SOliver Ruiz Dorantes void BluetoothServer::ReadyToRun(void) 78e5da0ec5SOliver Ruiz Dorantes { 79734ab97cSOliver Ruiz Dorantes fDeviceManager->StartMonitoringDevice("bluetooth/h2"); 80734ab97cSOliver Ruiz Dorantes fDeviceManager->StartMonitoringDevice("bluetooth/h3"); 81734ab97cSOliver Ruiz Dorantes fDeviceManager->StartMonitoringDevice("bluetooth/h4"); 82734ab97cSOliver Ruiz Dorantes fDeviceManager->StartMonitoringDevice("bluetooth/h5"); 8330f1d1f3SOliver Ruiz Dorantes // Launch the notifier thread 8430f1d1f3SOliver Ruiz Dorantes if ( resume_thread(fEventListener) != B_OK ) 8530f1d1f3SOliver Ruiz Dorantes { 8630f1d1f3SOliver Ruiz Dorantes Output::Instance()->Post("Bluetooth port listener failed\n", BLACKBOARD_GENERAL); 8730f1d1f3SOliver Ruiz Dorantes } 8830f1d1f3SOliver Ruiz Dorantes 8930f1d1f3SOliver Ruiz Dorantes Output::Instance()->Post("Bluetooth server Ready\n", BLACKBOARD_GENERAL); 9030f1d1f3SOliver Ruiz Dorantes } 9130f1d1f3SOliver Ruiz Dorantes 9230f1d1f3SOliver Ruiz Dorantes 93e5da0ec5SOliver Ruiz Dorantes void BluetoothServer::AppActivated(bool act) 94e5da0ec5SOliver Ruiz Dorantes { 9530f1d1f3SOliver Ruiz Dorantes printf("Activated %d\n",act); 9630f1d1f3SOliver Ruiz Dorantes } 9730f1d1f3SOliver Ruiz Dorantes 9830f1d1f3SOliver Ruiz Dorantes 9930f1d1f3SOliver Ruiz Dorantes void BluetoothServer::MessageReceived(BMessage *message) 10030f1d1f3SOliver Ruiz Dorantes { 10130f1d1f3SOliver Ruiz Dorantes BMessage reply; 102e5da0ec5SOliver Ruiz Dorantes status_t status = B_WOULD_BLOCK; 103e5da0ec5SOliver Ruiz Dorantes // mark somehow.. do not reply anything 10430f1d1f3SOliver Ruiz Dorantes 10530f1d1f3SOliver Ruiz Dorantes switch(message->what) 10630f1d1f3SOliver Ruiz Dorantes { 10730f1d1f3SOliver Ruiz Dorantes case BT_MSG_ADD_DEVICE: 10830f1d1f3SOliver Ruiz Dorantes { 10930f1d1f3SOliver Ruiz Dorantes BString str; 11030f1d1f3SOliver Ruiz Dorantes message->FindString("name", &str); 11130f1d1f3SOliver Ruiz Dorantes BPath path(str.String()); 112e5da0ec5SOliver Ruiz Dorantes Output::Instance()->Postf(BLACKBOARD_GENERAL, 113e5da0ec5SOliver Ruiz Dorantes "Requested LocalDevice %s\n", str.String()); 11430f1d1f3SOliver Ruiz Dorantes LocalDeviceImpl* ldi = LocalDeviceImpl::CreateTransportAccessor(&path); 11530f1d1f3SOliver Ruiz Dorantes 11630f1d1f3SOliver Ruiz Dorantes if (ldi->GetID() >= 0) { 11730f1d1f3SOliver Ruiz Dorantes fLocalDevicesList.AddItem(ldi); 118b48fa68aSOliver Ruiz Dorantes Output::Instance()->AddTab("Local Device", BLACKBOARD_LD(ldi->GetID())); 119e5da0ec5SOliver Ruiz Dorantes Output::Instance()->Postf(BLACKBOARD_LD(ldi->GetID()), 120e5da0ec5SOliver Ruiz Dorantes "LocalDevice %s id=%x added\n", 121e5da0ec5SOliver Ruiz Dorantes str.String(), ldi->GetID()); 12230f1d1f3SOliver Ruiz Dorantes } else { 123e5da0ec5SOliver Ruiz Dorantes Output::Instance()->Post("Adding LocalDevice failed\n", 124e5da0ec5SOliver Ruiz Dorantes BLACKBOARD_GENERAL); 12530f1d1f3SOliver Ruiz Dorantes } 12630f1d1f3SOliver Ruiz Dorantes 12730f1d1f3SOliver Ruiz Dorantes status = B_WOULD_BLOCK; 128d04eb939SOliver Ruiz Dorantes /* TODO: This should be by user request only! */ 129d04eb939SOliver Ruiz Dorantes ldi->Launch(); 13030f1d1f3SOliver Ruiz Dorantes } 131e5da0ec5SOliver Ruiz Dorantes break; 13230f1d1f3SOliver Ruiz Dorantes case BT_MSG_COUNT_LOCAL_DEVICES: 13330f1d1f3SOliver Ruiz Dorantes status = HandleLocalDevicesCount(message, &reply); 13430f1d1f3SOliver Ruiz Dorantes break; 135057d0dc0SOliver Ruiz Dorantes case BT_MSG_ACQUIRE_LOCAL_DEVICE: 13630f1d1f3SOliver Ruiz Dorantes status = HandleAcquireLocalDevice(message, &reply); 13730f1d1f3SOliver Ruiz Dorantes break; 13830f1d1f3SOliver Ruiz Dorantes 13930f1d1f3SOliver Ruiz Dorantes case BT_MSG_HANDLE_SIMPLE_REQUEST: 14030f1d1f3SOliver Ruiz Dorantes status = HandleSimpleRequest(message, &reply); 14130f1d1f3SOliver Ruiz Dorantes break; 1423fdaa5bfSOliver Ruiz Dorantes case BT_MSG_GET_PROPERTY: 1433fdaa5bfSOliver Ruiz Dorantes status = HandleGetProperty(message, &reply); 1443fdaa5bfSOliver Ruiz Dorantes break; 1453fdaa5bfSOliver Ruiz Dorantes 146009fac99SOliver Ruiz Dorantes /* Handle if the bluetooth preferences is running?? */ 14730f1d1f3SOliver Ruiz Dorantes case B_SOME_APP_LAUNCHED: 14830f1d1f3SOliver Ruiz Dorantes { 14930f1d1f3SOliver Ruiz Dorantes const char *signature; 15030f1d1f3SOliver Ruiz Dorantes // TODO: what's this for? 15130f1d1f3SOliver Ruiz Dorantes if (message->FindString("be:signature", &signature) == B_OK) { 15230f1d1f3SOliver Ruiz Dorantes printf("input_server : %s\n", signature); 15330f1d1f3SOliver Ruiz Dorantes if (strcmp(signature, "application/x-vnd.Be-TSKB") == 0) { 15430f1d1f3SOliver Ruiz Dorantes 15530f1d1f3SOliver Ruiz Dorantes } 15630f1d1f3SOliver Ruiz Dorantes } 15730f1d1f3SOliver Ruiz Dorantes return; 15830f1d1f3SOliver Ruiz Dorantes } 15930f1d1f3SOliver Ruiz Dorantes 16030f1d1f3SOliver Ruiz Dorantes default: 16130f1d1f3SOliver Ruiz Dorantes BApplication::MessageReceived(message); 16230f1d1f3SOliver Ruiz Dorantes break; 16330f1d1f3SOliver Ruiz Dorantes } 16430f1d1f3SOliver Ruiz Dorantes 165009fac99SOliver Ruiz Dorantes // Can we reply right now? 166009fac99SOliver Ruiz Dorantes // TOD: review this condition 16730f1d1f3SOliver Ruiz Dorantes if (status != B_WOULD_BLOCK) { 16830f1d1f3SOliver Ruiz Dorantes reply.AddInt32("status", status); 16930f1d1f3SOliver Ruiz Dorantes message->SendReply(&reply); 17030f1d1f3SOliver Ruiz Dorantes printf("Sending reply message\n"); 17130f1d1f3SOliver Ruiz Dorantes } 17230f1d1f3SOliver Ruiz Dorantes } 17330f1d1f3SOliver Ruiz Dorantes 17430f1d1f3SOliver Ruiz Dorantes #if 0 17530f1d1f3SOliver Ruiz Dorantes #pragma mark - 17630f1d1f3SOliver Ruiz Dorantes #endif 17730f1d1f3SOliver Ruiz Dorantes 17830f1d1f3SOliver Ruiz Dorantes LocalDeviceImpl* 17930f1d1f3SOliver Ruiz Dorantes BluetoothServer::LocateDelegateFromMessage(BMessage* message) 18030f1d1f3SOliver Ruiz Dorantes { 18130f1d1f3SOliver Ruiz Dorantes LocalDeviceImpl* ldi = NULL; 18230f1d1f3SOliver Ruiz Dorantes hci_id hid; 18330f1d1f3SOliver Ruiz Dorantes 184e5da0ec5SOliver Ruiz Dorantes if (message->FindInt32("hci_id", &hid) == B_OK) { 18530f1d1f3SOliver Ruiz Dorantes /* Try to find out when a ID was specified */ 18630f1d1f3SOliver Ruiz Dorantes int index; 18730f1d1f3SOliver Ruiz Dorantes for (index = 0; index < fLocalDevicesList.CountItems(); index ++) { 18830f1d1f3SOliver Ruiz Dorantes ldi = fLocalDevicesList.ItemAt(index); 189e5da0ec5SOliver Ruiz Dorantes if (ldi->GetID() == hid) 19030f1d1f3SOliver Ruiz Dorantes break; 19130f1d1f3SOliver Ruiz Dorantes } 19230f1d1f3SOliver Ruiz Dorantes } 19330f1d1f3SOliver Ruiz Dorantes 19430f1d1f3SOliver Ruiz Dorantes return ldi; 195e5da0ec5SOliver Ruiz Dorantes 19630f1d1f3SOliver Ruiz Dorantes } 19730f1d1f3SOliver Ruiz Dorantes 19830f1d1f3SOliver Ruiz Dorantes LocalDeviceImpl* 19930f1d1f3SOliver Ruiz Dorantes BluetoothServer::LocateLocalDeviceImpl(hci_id hid) 20030f1d1f3SOliver Ruiz Dorantes { 20130f1d1f3SOliver Ruiz Dorantes /* Try to find out when a ID was specified */ 20230f1d1f3SOliver Ruiz Dorantes int index; 20330f1d1f3SOliver Ruiz Dorantes 20430f1d1f3SOliver Ruiz Dorantes for (index = 0; index < fLocalDevicesList.CountItems(); index ++) { 20530f1d1f3SOliver Ruiz Dorantes LocalDeviceImpl* ldi = fLocalDevicesList.ItemAt(index); 206e5da0ec5SOliver Ruiz Dorantes if (ldi->GetID() == hid) 20730f1d1f3SOliver Ruiz Dorantes return ldi; 20830f1d1f3SOliver Ruiz Dorantes } 20930f1d1f3SOliver Ruiz Dorantes 21030f1d1f3SOliver Ruiz Dorantes return NULL; 21130f1d1f3SOliver Ruiz Dorantes } 21230f1d1f3SOliver Ruiz Dorantes 21330f1d1f3SOliver Ruiz Dorantes 21430f1d1f3SOliver Ruiz Dorantes #if 0 21530f1d1f3SOliver Ruiz Dorantes #pragma - Messages reply 21630f1d1f3SOliver Ruiz Dorantes #endif 21730f1d1f3SOliver Ruiz Dorantes 21830f1d1f3SOliver Ruiz Dorantes status_t 21930f1d1f3SOliver Ruiz Dorantes BluetoothServer::HandleLocalDevicesCount(BMessage* message, BMessage* reply) 22030f1d1f3SOliver Ruiz Dorantes { 22130f1d1f3SOliver Ruiz Dorantes return reply->AddInt32("count", fLocalDevicesList.CountItems()); 22230f1d1f3SOliver Ruiz Dorantes } 22330f1d1f3SOliver Ruiz Dorantes 22430f1d1f3SOliver Ruiz Dorantes 22530f1d1f3SOliver Ruiz Dorantes status_t 22630f1d1f3SOliver Ruiz Dorantes BluetoothServer::HandleAcquireLocalDevice(BMessage* message, BMessage* reply) 22730f1d1f3SOliver Ruiz Dorantes { 22830f1d1f3SOliver Ruiz Dorantes hci_id hid; 22930f1d1f3SOliver Ruiz Dorantes ssize_t size; 23030f1d1f3SOliver Ruiz Dorantes bdaddr_t bdaddr; 23130f1d1f3SOliver Ruiz Dorantes LocalDeviceImpl* ldi = NULL; 2329306af4dSOliver Ruiz Dorantes static int32 lastIndex = 0; 23330f1d1f3SOliver Ruiz Dorantes 23430f1d1f3SOliver Ruiz Dorantes if (message->FindInt32("hci_id", &hid) == B_OK) 23530f1d1f3SOliver Ruiz Dorantes { 236e5da0ec5SOliver Ruiz Dorantes Output::Instance()->Post("GetLocalDevice requested with id\n", 237e5da0ec5SOliver Ruiz Dorantes BLACKBOARD_KIT); 23830f1d1f3SOliver Ruiz Dorantes ldi = LocateDelegateFromMessage(message); 23930f1d1f3SOliver Ruiz Dorantes 240e5da0ec5SOliver Ruiz Dorantes } else if (message->FindData("bdaddr", B_ANY_TYPE, (const void**)&bdaddr, &size ) 241e5da0ec5SOliver Ruiz Dorantes == B_OK) { 24230f1d1f3SOliver Ruiz Dorantes /* Try to find out when the user specified the address */ 243e5da0ec5SOliver Ruiz Dorantes Output::Instance()->Post("GetLocalDevice requested with bdaddr\n", 244e5da0ec5SOliver Ruiz Dorantes BLACKBOARD_KIT); 2459306af4dSOliver Ruiz Dorantes for (lastIndex = 0; lastIndex < fLocalDevicesList.CountItems(); lastIndex ++) { 2469306af4dSOliver Ruiz Dorantes //TODO: Only possible if the property is available 2479306af4dSOliver Ruiz Dorantes //bdaddr_t local; 2489306af4dSOliver Ruiz Dorantes //ldi = fLocalDevicesList.ItemAt(lastIndex); 249e5da0ec5SOliver Ruiz Dorantes //if ((ldi->GetAddress(&local, message) == B_OK) 250e5da0ec5SOliver Ruiz Dorantes // && bacmp(&local, &bdaddr)) { 251fbbf64a4SOliver Ruiz Dorantes // break; 252fbbf64a4SOliver Ruiz Dorantes //} 25330f1d1f3SOliver Ruiz Dorantes } 25430f1d1f3SOliver Ruiz Dorantes 255e5da0ec5SOliver Ruiz Dorantes } else { 2569306af4dSOliver Ruiz Dorantes // Careless, any device not performing operations will be fine 2579306af4dSOliver Ruiz Dorantes Output::Instance()->Post("GetLocalDevice plain request\n", BLACKBOARD_KIT); 2589306af4dSOliver Ruiz Dorantes // from last assigned till end 2599306af4dSOliver Ruiz Dorantes for ( int index = lastIndex + 1; index < fLocalDevicesList.CountItems(); index ++) { 26030f1d1f3SOliver Ruiz Dorantes ldi = fLocalDevicesList.ItemAt(index); 26130f1d1f3SOliver Ruiz Dorantes printf("Requesting local device %ld\n", ldi->GetID()); 26230f1d1f3SOliver Ruiz Dorantes if (ldi != NULL && ldi->Available()) 26330f1d1f3SOliver Ruiz Dorantes { 2649306af4dSOliver Ruiz Dorantes Output::Instance()->Postf(BLACKBOARD_KIT, "Device available: %lx\n", ldi->GetID()); 2659306af4dSOliver Ruiz Dorantes lastIndex = index; 2669306af4dSOliver Ruiz Dorantes break; 2679306af4dSOliver Ruiz Dorantes } 2689306af4dSOliver Ruiz Dorantes } 2699306af4dSOliver Ruiz Dorantes 2709306af4dSOliver Ruiz Dorantes // from starting till last assigned if not yet found 2719306af4dSOliver Ruiz Dorantes if (ldi == NULL) { 2729306af4dSOliver Ruiz Dorantes for ( int index = 0; index <= lastIndex ; index ++) { 2739306af4dSOliver Ruiz Dorantes ldi = fLocalDevicesList.ItemAt(index); 2749306af4dSOliver Ruiz Dorantes printf("Requesting local device %ld\n", ldi->GetID()); 2759306af4dSOliver Ruiz Dorantes if (ldi != NULL && ldi->Available()) 2769306af4dSOliver Ruiz Dorantes { 2779306af4dSOliver Ruiz Dorantes Output::Instance()->Postf(BLACKBOARD_KIT, "Device available: %lx\n", ldi->GetID()); 2789306af4dSOliver Ruiz Dorantes lastIndex = index; 27930f1d1f3SOliver Ruiz Dorantes break; 28030f1d1f3SOliver Ruiz Dorantes } 28130f1d1f3SOliver Ruiz Dorantes } 28230f1d1f3SOliver Ruiz Dorantes } 2839306af4dSOliver Ruiz Dorantes } 28430f1d1f3SOliver Ruiz Dorantes 2859306af4dSOliver Ruiz Dorantes if (lastIndex <= fLocalDevicesList.CountItems() && ldi != NULL && ldi->Available()) { 2869306af4dSOliver Ruiz Dorantes hid = ldi->GetID(); 28730f1d1f3SOliver Ruiz Dorantes ldi->Acquire(); 2889306af4dSOliver Ruiz Dorantes 2899306af4dSOliver Ruiz Dorantes Output::Instance()->Postf(BLACKBOARD_KIT, "Device acquired %lx\n", hid); 29030f1d1f3SOliver Ruiz Dorantes return reply->AddInt32("hci_id", hid); 29130f1d1f3SOliver Ruiz Dorantes } 29230f1d1f3SOliver Ruiz Dorantes 29330f1d1f3SOliver Ruiz Dorantes return B_ERROR; 29430f1d1f3SOliver Ruiz Dorantes 29530f1d1f3SOliver Ruiz Dorantes } 29630f1d1f3SOliver Ruiz Dorantes 29730f1d1f3SOliver Ruiz Dorantes 29830f1d1f3SOliver Ruiz Dorantes status_t 29930f1d1f3SOliver Ruiz Dorantes BluetoothServer::HandleSimpleRequest(BMessage* message, BMessage* reply) 30030f1d1f3SOliver Ruiz Dorantes { 30130f1d1f3SOliver Ruiz Dorantes LocalDeviceImpl* ldi = LocateDelegateFromMessage(message); 3023fdaa5bfSOliver Ruiz Dorantes const char* propertyRequested; 30330f1d1f3SOliver Ruiz Dorantes 30430f1d1f3SOliver Ruiz Dorantes // Find out if there is a property being requested, 30530f1d1f3SOliver Ruiz Dorantes if (message->FindString("property", &propertyRequested) == B_OK) { 30630f1d1f3SOliver Ruiz Dorantes // Check if the property has been already retrieved 30730f1d1f3SOliver Ruiz Dorantes if (ldi->IsPropertyAvailable(propertyRequested)) { 30830f1d1f3SOliver Ruiz Dorantes // Dump everything 30930f1d1f3SOliver Ruiz Dorantes reply->AddMessage("properties",ldi->GetPropertiesMessage()); 31030f1d1f3SOliver Ruiz Dorantes return B_OK; 31130f1d1f3SOliver Ruiz Dorantes } 31230f1d1f3SOliver Ruiz Dorantes } 31330f1d1f3SOliver Ruiz Dorantes 31430f1d1f3SOliver Ruiz Dorantes // we are gonna need issue the command ... 31530f1d1f3SOliver Ruiz Dorantes if (ldi->ProcessSimpleRequest(DetachCurrentMessage()) == B_OK) 31630f1d1f3SOliver Ruiz Dorantes return B_WOULD_BLOCK; 31730f1d1f3SOliver Ruiz Dorantes else 31830f1d1f3SOliver Ruiz Dorantes return B_ERROR; 31930f1d1f3SOliver Ruiz Dorantes 32030f1d1f3SOliver Ruiz Dorantes } 32130f1d1f3SOliver Ruiz Dorantes 32230f1d1f3SOliver Ruiz Dorantes 3233fdaa5bfSOliver Ruiz Dorantes status_t 3243fdaa5bfSOliver Ruiz Dorantes BluetoothServer::HandleGetProperty(BMessage* message, BMessage* reply) 3253fdaa5bfSOliver Ruiz Dorantes { 3263fdaa5bfSOliver Ruiz Dorantes /* User side will look for the reply in a result field 3273fdaa5bfSOliver Ruiz Dorantes * and will not care about status fields, therefore we return OK in all cases 3283fdaa5bfSOliver Ruiz Dorantes */ 3293fdaa5bfSOliver Ruiz Dorantes 3303fdaa5bfSOliver Ruiz Dorantes LocalDeviceImpl* ldi = LocateDelegateFromMessage(message); 3313fdaa5bfSOliver Ruiz Dorantes const char* propertyRequested; 3323fdaa5bfSOliver Ruiz Dorantes 3333fdaa5bfSOliver Ruiz Dorantes // Find out if there is a property being requested, 3343fdaa5bfSOliver Ruiz Dorantes if (message->FindString("property", &propertyRequested) == B_OK) { 3353fdaa5bfSOliver Ruiz Dorantes 3363fdaa5bfSOliver Ruiz Dorantes Output::Instance()->Postf(BLACKBOARD_LD(ldi->GetID()), "Searching %s property...\n", 3373fdaa5bfSOliver Ruiz Dorantes propertyRequested); 3383fdaa5bfSOliver Ruiz Dorantes 3393fdaa5bfSOliver Ruiz Dorantes // Check if the property has been already retrieved 3403fdaa5bfSOliver Ruiz Dorantes if (ldi->IsPropertyAvailable(propertyRequested)) { 341*dd5df905SOliver Ruiz Dorantes if (strcmp(propertyRequested, "hci_version") == 0 342*dd5df905SOliver Ruiz Dorantes || strcmp(propertyRequested, "lmp_version") == 0 343*dd5df905SOliver Ruiz Dorantes || strcmp(propertyRequested, "sco_mtu") == 0) { 344*dd5df905SOliver Ruiz Dorantes 3453fdaa5bfSOliver Ruiz Dorantes uint8 result = ldi->GetPropertiesMessage()->FindInt8(propertyRequested); 3463fdaa5bfSOliver Ruiz Dorantes reply->AddInt32("result", result); 347*dd5df905SOliver Ruiz Dorantes 348*dd5df905SOliver Ruiz Dorantes } else if (strcmp(propertyRequested, "hci_revision") == 0 349*dd5df905SOliver Ruiz Dorantes || strcmp(propertyRequested, "lmp_subversion") == 0 350*dd5df905SOliver Ruiz Dorantes || strcmp(propertyRequested, "manufacturer") == 0 351*dd5df905SOliver Ruiz Dorantes || strcmp(propertyRequested, "acl_mtu") == 0 352*dd5df905SOliver Ruiz Dorantes || strcmp(propertyRequested, "acl_max_pkt") == 0 353*dd5df905SOliver Ruiz Dorantes || strcmp(propertyRequested, "sco_max_pkt") == 0 ) { 354*dd5df905SOliver Ruiz Dorantes 3553fdaa5bfSOliver Ruiz Dorantes uint16 result = ldi->GetPropertiesMessage()->FindInt16(propertyRequested); 3563fdaa5bfSOliver Ruiz Dorantes reply->AddInt32("result", result); 357*dd5df905SOliver Ruiz Dorantes 3583fdaa5bfSOliver Ruiz Dorantes } else { 3593fdaa5bfSOliver Ruiz Dorantes Output::Instance()->Postf(BLACKBOARD_LD(ldi->GetID()), "Property %s could not be satisfied\n", 3603fdaa5bfSOliver Ruiz Dorantes propertyRequested); 3613fdaa5bfSOliver Ruiz Dorantes } 3623fdaa5bfSOliver Ruiz Dorantes } 3633fdaa5bfSOliver Ruiz Dorantes } 3643fdaa5bfSOliver Ruiz Dorantes 3653fdaa5bfSOliver Ruiz Dorantes return B_OK; 3663fdaa5bfSOliver Ruiz Dorantes } 3673fdaa5bfSOliver Ruiz Dorantes 36830f1d1f3SOliver Ruiz Dorantes #if 0 36930f1d1f3SOliver Ruiz Dorantes #pragma mark - 37030f1d1f3SOliver Ruiz Dorantes #endif 37130f1d1f3SOliver Ruiz Dorantes 37230f1d1f3SOliver Ruiz Dorantes 37330f1d1f3SOliver Ruiz Dorantes int32 37430f1d1f3SOliver Ruiz Dorantes BluetoothServer::notification_Thread(void* data) 37530f1d1f3SOliver Ruiz Dorantes { 37630f1d1f3SOliver Ruiz Dorantes BPortNot notifierd((BluetoothServer*)data, BT_USERLAND_PORT_NAME); 37730f1d1f3SOliver Ruiz Dorantes 37830f1d1f3SOliver Ruiz Dorantes notifierd.loop(); 37930f1d1f3SOliver Ruiz Dorantes return B_NO_ERROR; 38030f1d1f3SOliver Ruiz Dorantes } 38130f1d1f3SOliver Ruiz Dorantes 38230f1d1f3SOliver Ruiz Dorantes int32 38330f1d1f3SOliver Ruiz Dorantes BluetoothServer::sdp_server_Thread(void* data) 38430f1d1f3SOliver Ruiz Dorantes { 38530f1d1f3SOliver Ruiz Dorantes 38630f1d1f3SOliver Ruiz Dorantes return B_NO_ERROR; 38730f1d1f3SOliver Ruiz Dorantes } 38830f1d1f3SOliver Ruiz Dorantes 38930f1d1f3SOliver Ruiz Dorantes 39030f1d1f3SOliver Ruiz Dorantes void 39130f1d1f3SOliver Ruiz Dorantes BluetoothServer::ShowWindow(BWindow* pWindow) 39230f1d1f3SOliver Ruiz Dorantes { 39330f1d1f3SOliver Ruiz Dorantes pWindow->Lock(); 39430f1d1f3SOliver Ruiz Dorantes if (pWindow->IsHidden()) 39530f1d1f3SOliver Ruiz Dorantes pWindow->Show(); 39630f1d1f3SOliver Ruiz Dorantes else 39730f1d1f3SOliver Ruiz Dorantes pWindow->Activate(); 39830f1d1f3SOliver Ruiz Dorantes pWindow->Unlock(); 39930f1d1f3SOliver Ruiz Dorantes } 40030f1d1f3SOliver Ruiz Dorantes 40130f1d1f3SOliver Ruiz Dorantes 40230f1d1f3SOliver Ruiz Dorantes #if 0 40330f1d1f3SOliver Ruiz Dorantes #pragma mark - 40430f1d1f3SOliver Ruiz Dorantes #endif 40530f1d1f3SOliver Ruiz Dorantes 40630f1d1f3SOliver Ruiz Dorantes int 40730f1d1f3SOliver Ruiz Dorantes main(int /*argc*/, char** /*argv*/) 40830f1d1f3SOliver Ruiz Dorantes { 40930f1d1f3SOliver Ruiz Dorantes setbuf(stdout, NULL); 41030f1d1f3SOliver Ruiz Dorantes 41130f1d1f3SOliver Ruiz Dorantes BluetoothServer* bluetoothServer = new BluetoothServer; 41230f1d1f3SOliver Ruiz Dorantes 41330f1d1f3SOliver Ruiz Dorantes bluetoothServer->Run(); 41430f1d1f3SOliver Ruiz Dorantes delete bluetoothServer; 41530f1d1f3SOliver Ruiz Dorantes 41630f1d1f3SOliver Ruiz Dorantes return 0; 41730f1d1f3SOliver Ruiz Dorantes } 41830f1d1f3SOliver Ruiz Dorantes 419