- Remove size output parameter creating commands

- Add support for reading the size of internals buffers of the bt chips
- Add support for Resetting the Device
- Add broadcom vendor command fro writting the bdaddr
- clean up the debug output



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29669 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes 2009-03-23 23:07:07 +00:00
parent ce65700663
commit dd5df90570
7 changed files with 100 additions and 41 deletions

View File

@ -351,9 +351,14 @@ struct hci_command_header {
#define OGF_STATUS_PARAM 0x05
/* Testing commands */
#define OGF_TESTING_CMD 0x3E
#define OGF_TESTING_CMD 0x06
/* Vendor specific commands */
#define OGF_VENDOR_CMD 0x3F
#define OCF_WRITE_BCM2035_BDADDR 0x01
struct hci_write_bcm2035_bdaddr {
bdaddr_t bdaddr;
} _PACKED;
#endif // _BTHCI_COMMAND_H_

View File

@ -52,6 +52,8 @@ private:
virtual ~LocalDevice();
status_t ReadLocalVersion();
status_t ReadBufferSize();
status_t Reset();
hci_id GetID(void) {return hid;}
static LocalDevice* RequestLocalDeviceID(BMessage* request);

View File

@ -20,7 +20,7 @@ template <typename Type = void, int paramSize = 0, int HeaderSize = HCI_COMMAND_
class BluetoothCommand {
public:
BluetoothCommand(uint8 ogf, uint8 ocf, size_t* outsize)
BluetoothCommand(uint8 ogf, uint8 ocf)
{
fHeader = (struct hci_command_header*) fBuffer;
@ -31,8 +31,6 @@ public:
fHeader->opcode = B_HOST_TO_LENDIAN_INT16(PACK_OPCODE(ogf, ocf));
fHeader->clen = paramSize;
*outsize = HeaderSize + paramSize;
}
Type*
@ -47,6 +45,11 @@ public:
return (void*)fBuffer;
}
size_t Size() const
{
return HeaderSize + paramSize;
}
private:
char fBuffer[paramSize + HeaderSize];
Type* fContent;

View File

@ -66,7 +66,7 @@ BPortNot::loop()
ld = ourapp->LocateLocalDeviceImpl(GET_PORTCODE_HID(code));
if (ld == NULL) {
Output::Instance()->Post("LocalDevice could not be fetched", BLACKBOARD_EVENTS);
Output::Instance()->Post("LocalDevice could not be fetched", BLACKBOARD_GENERAL);
continue;
}

View File

@ -35,7 +35,6 @@ BluetoothServer::BluetoothServer() : BApplication(BLUETOOTH_SIGNATURE)
Output::Instance()->AddTab("General", BLACKBOARD_GENERAL);
Output::Instance()->AddTab("Device Manager", BLACKBOARD_DEVICEMANAGER);
Output::Instance()->AddTab("Events", BLACKBOARD_EVENTS);
Output::Instance()->AddTab("Kit", BLACKBOARD_KIT);
ShowWindow(Output::Instance());
@ -339,21 +338,23 @@ BluetoothServer::HandleGetProperty(BMessage* message, BMessage* reply)
// Check if the property has been already retrieved
if (ldi->IsPropertyAvailable(propertyRequested)) {
if (strcmp(propertyRequested, "hci_version") == 0) {
if (strcmp(propertyRequested, "hci_version") == 0
|| strcmp(propertyRequested, "lmp_version") == 0
|| strcmp(propertyRequested, "sco_mtu") == 0) {
uint8 result = ldi->GetPropertiesMessage()->FindInt8(propertyRequested);
reply->AddInt32("result", result);
} else if (strcmp(propertyRequested, "hci_revision") == 0) {
uint16 result = ldi->GetPropertiesMessage()->FindInt16(propertyRequested);
reply->AddInt32("result", result);
} else if (strcmp(propertyRequested, "lmp_version") == 0) {
uint8 result = ldi->GetPropertiesMessage()->FindInt8(propertyRequested);
reply->AddInt32("result", result);
} else if (strcmp(propertyRequested, "lmp_subversion") == 0) {
uint16 result = ldi->GetPropertiesMessage()->FindInt16(propertyRequested);
reply->AddInt32("result", result);
} else if (strcmp(propertyRequested, "manufacturer") == 0) {
} else if (strcmp(propertyRequested, "hci_revision") == 0
|| strcmp(propertyRequested, "lmp_subversion") == 0
|| strcmp(propertyRequested, "manufacturer") == 0
|| strcmp(propertyRequested, "acl_mtu") == 0
|| strcmp(propertyRequested, "acl_max_pkt") == 0
|| strcmp(propertyRequested, "sco_max_pkt") == 0 ) {
uint16 result = ldi->GetPropertiesMessage()->FindInt16(propertyRequested);
reply->AddInt32("result", result);
} else {
Output::Instance()->Postf(BLACKBOARD_LD(ldi->GetID()), "Property %s could not be satisfied\n",
propertyRequested);

View File

@ -29,7 +29,6 @@
typedef enum {
BLACKBOARD_GENERAL = 0,
BLACKBOARD_DEVICEMANAGER,
BLACKBOARD_EVENTS,
BLACKBOARD_KIT,
// more blackboards
BLACKBOARD_END

View File

@ -99,22 +99,28 @@ printf("### \n");
// Check if its a requested one
if ( event->ecode == HCI_EVENT_CMD_COMPLETE ) {
(Output::Instance()->Post("Incoming Command Complete\n", BLACKBOARD_EVENTS));
request = FindPetition(event->ecode, ((struct hci_ev_cmd_complete*)(event+1))->opcode, &eventIndexLocation );
/*
(Output::Instance()->Postf(BLACKBOARD_LD(GetID()), "Command Complete, n commands %d\n",
((struct hci_ev_cmd_complete*)event)->ncmd));
*/
request = FindPetition(event->ecode, ((struct hci_ev_cmd_complete*)(event+1))->opcode,
&eventIndexLocation);
} else if ( event->ecode == HCI_EVENT_CMD_STATUS ) {
(Output::Instance()->Post("Incoming Command Status\n", BLACKBOARD_EVENTS));
request = FindPetition(event->ecode, ((struct hci_ev_cmd_status*)(event+1))->opcode, &eventIndexLocation );
/*(Output::Instance()->Postf(BLACKBOARD_LD(GetID()), "Command Status, n commands %d status %x\n",
((struct hci_ev_cmd_status*)event)->ncmd,
((struct hci_ev_cmd_status*)event)->status ));
*/
request = FindPetition(event->ecode, ((struct hci_ev_cmd_status*)(event+1))->opcode,
&eventIndexLocation);
} else
{
} else {
request = FindPetition(event->ecode);
}
if ( request == NULL) {
(Output::Instance()->Post("Event could not be understood or delivered\n", BLACKBOARD_EVENTS));
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"Event %x could not be understood or delivered\n", event->ecode);
return;
}
@ -245,18 +251,17 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* re
Output::Instance()->Post("Nobody waiting for the event\n", BLACKBOARD_KIT);
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s for command %s\n",__FUNCTION__, GetCommand(opcodeExpected));
switch (opcodeExpected) {
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s(%d) for %s\n",__FUNCTION__, event->ncmd,GetCommand(opcodeExpected));
switch ((uint16)opcodeExpected) {
case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_LOCAL_VERSION):
{
struct hci_rp_read_loc_version* version = (struct hci_rp_read_loc_version*)(event+1);
reply.AddInt8("status", version->status);
if (version->status == BT_OK) {
//reply.AddData("version", B_ANY_TYPE, &version, sizeof(struct hci_rp_read_loc_version));
reply.AddInt8("status", version->status);
printf("Sending reply ... %ld\n", request->SendReply(&reply));
reply.PrintToStream();
@ -284,6 +289,37 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* re
}
break;
case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BUFFER_SIZE):
{
struct hci_rp_read_buffer_size* buffer = (struct hci_rp_read_buffer_size*)(event+1);
reply.AddInt8("status", buffer->status);
if (buffer->status == BT_OK) {
printf("Sending reply ... %ld\n", request->SendReply(&reply));
reply.PrintToStream();
if (!IsPropertyAvailable("acl_mtu"))
fProperties->AddInt16("acl_mtu", buffer->acl_mtu);
if (!IsPropertyAvailable("sco_mtu"))
fProperties->AddInt8("sco_mtu", buffer->sco_mtu);
if (!IsPropertyAvailable("acl_max_pkt"))
fProperties->AddInt16("acl_max_pkt", buffer->acl_max_pkt);
if (!IsPropertyAvailable("sco_max_pkt"))
fProperties->AddInt16("sco_max_pkt", buffer->sco_max_pkt);
Output::Instance()->Postf(BLACKBOARD_KIT, "Reply for Read Buffer Size %x\n", buffer->status);
}
// This request is not gonna be used anymore
ClearWantedEvent(request);
}
break;
case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BD_ADDR):
{
struct hci_rp_read_bd_addr* readbdaddr = (struct hci_rp_read_bd_addr*)(event+1);
@ -383,6 +419,7 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* re
ClearWantedEvent(request);
}
break;
case PACK_OPCODE(OGF_LINK_CONTROL, OCF_PIN_CODE_REPLY):
{
uint8* statusReply = (uint8*)(event+1);
@ -432,7 +469,22 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* re
ClearWantedEvent(request);
}
break;
// place here all CC that just replies a uint8 status
case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_RESET):
case PACK_OPCODE(OGF_VENDOR_CMD, OCF_WRITE_BCM2035_BDADDR):
{
reply.AddInt8("status", *(uint8*)(event+1));
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s for %s status %x\n",
__FUNCTION__,GetCommand(opcodeExpected), *(uint8*)(event+1));
request->SendReply(&reply);
ClearWantedEvent(request);
}
break;
default:
Output::Instance()->Post("Command Complete not handled\n", BLACKBOARD_KIT);
break;
@ -457,7 +509,7 @@ LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, BMessage* reques
if (request->IsSourceWaiting() == false)
Output::Instance()->Post("Nobody waiting for the event\n", BLACKBOARD_KIT);
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s for command %s\n",__FUNCTION__, GetCommand(opcodeExpected));
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s(%d) for command %s\n",__FUNCTION__, event->ncmd,GetCommand(opcodeExpected));
switch (opcodeExpected) {
@ -577,9 +629,7 @@ LocalDeviceImpl::ConnectionRequest(struct hci_ev_conn_request* event, BMessage*
size_t size;
void* command;
printf("Connection type %d from %s\n", event->link_type, bdaddrUtils::ToString(event->bdaddr));
(Output::Instance()->Post("Connection Incoming ...\n", BLACKBOARD_EVENTS));
Output::Instance()->Postf(BLACKBOARD_LD(GetID()), "Connection Incoming type %x from %s...\n", event->link_type, bdaddrUtils::ToString(event->bdaddr));
/* TODO: add a possible request in the queue */
if (true) { // Check Preferences if we are to accept this connection
@ -598,13 +648,12 @@ LocalDeviceImpl::ConnectionRequest(struct hci_ev_conn_request* event, BMessage*
AddWantedEvent(newrequest);
if ((fHCIDelegate)->IssueCommand(command, size) == B_ERROR) {
(Output::Instance()->Post("Command issue error for ConnAccpq\n", BLACKBOARD_EVENTS));
Output::Instance()->Postf(BLACKBOARD_LD(GetID()), "Command issue error for ConnAccpq\n");
// remove the request
}
else {
(Output::Instance()->Post("Command issued for ConnAccp\n", BLACKBOARD_EVENTS));
Output::Instance()->Postf(BLACKBOARD_LD(GetID()), "Command issue for ConnAccpq\n");
}
}
@ -690,7 +739,7 @@ LocalDeviceImpl::ProcessSimpleRequest(BMessage* request)
if (((HCITransportAccessor*)fHCIDelegate)->IssueCommand(command, size) == B_ERROR) {
// TODO: - Reply the request with error!
// - Remove the just added request
(Output::Instance()->Post("Command issue error\n", BLACKBOARD_EVENTS));
(Output::Instance()->Post("Command issue error\n", BLACKBOARD_KIT));
}
else {