bluetooth: Make RemoteDevice::Authenticate actually pair after

connecting

Sends an auth request to the controller, if connection was initated by
us

Change-Id: I32af0a24b902d0223bb4e773258ea9e9749a899c
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10527
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
vighnesh-sawant
2026-03-16 12:19:26 +00:00
committed by waddlesplash
parent aa864b9d41
commit c122595a54
5 changed files with 80 additions and 4 deletions
@@ -123,6 +123,7 @@ void* buildRejectConnectionRequest(bdaddr_t bdaddr, size_t* outsize);
void* buildIOCapabilityRequestReply(bdaddr_t bdaddr, uint8 capability, uint8 oob_data,
uint8 authentication, size_t* outsize);
void* buildUserConfirmReply(bdaddr_t bdaddr, size_t* outsize);
void* buildAuthenticationRequested(uint16 handle, size_t* outsize);
/* OGF_INFORMATIONAL_PARAM */
void* buildReadLocalVersionInformation(size_t* outsize);
+16
View File
@@ -299,6 +299,22 @@ buildUserConfirmReply(bdaddr_t bdaddr, size_t* outsize)
}
void*
buildAuthenticationRequested(uint16 handle, size_t* outsize)
{
CALLED();
struct hci_cp_auth_requested* param;
void* command = buildCommand(OGF_LINK_CONTROL, OCF_AUTH_REQUESTED, (void**)&param,
sizeof(struct hci_cp_auth_requested), outsize);
if (command != NULL)
param->handle = handle;
return command;
}
#if 0
#pragma mark - INFORMATIONAL_PARAM -
#endif
+26 -2
View File
@@ -188,10 +188,34 @@ RemoteDevice::Authenticate()
if (fMessenger->SendMessage(&request, &reply) == B_OK)
reply.FindInt8("status", &btStatus);
if (btStatus == BT_OK) {
if (btStatus != BT_OK)
return false;
reply.FindInt16("handle", (int16*)&fHandle);
BluetoothCommand<typed_command(hci_cp_auth_requested)> authRequest(OGF_LINK_CONTROL,
OCF_AUTH_REQUESTED);
authRequest->handle = fHandle;
BMessage authRequestMsg(BT_MSG_HANDLE_SIMPLE_REQUEST);
BMessage authReply;
authRequestMsg.AddInt32("hci_id", fDiscovererLocalDevice->ID());
authRequestMsg.AddData("raw command", B_ANY_TYPE, authRequest.Data(), authRequest.Size());
authRequestMsg.AddInt16("eventExpected", HCI_EVENT_CMD_STATUS);
authRequestMsg.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_AUTH_REQUESTED));
authRequestMsg.AddInt16("eventExpected", HCI_EVENT_AUTH_COMPLETE);
int8 authStatus = BT_ERROR;
if (fMessenger->SendMessage(&authRequestMsg, &authReply) == B_OK)
authReply.FindInt8("status", &authStatus);
if (authStatus == BT_OK)
return true;
} else
else
return false;
}
+35 -1
View File
@@ -166,7 +166,7 @@ LocalDeviceImpl::HandleExpectedRequest(struct hci_event_header* event,
break;
case HCI_EVENT_AUTH_COMPLETE:
AuthComplete(JumpEventHeader<struct hci_ev_auth_complete>(event), request);
break;
case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE:
@@ -821,6 +821,12 @@ LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event,
ClearWantedEvent(request, HCI_EVENT_CMD_STATUS, opcodeExpected);
} break;
case PACK_OPCODE(OGF_LINK_CONTROL, OCF_AUTH_REQUESTED):
{
TRACE_BT("LocalDeviceImpl: Command Status for auth requested %x\n", event->status);
ClearWantedEvent(request, HCI_EVENT_CMD_STATUS, opcodeExpected);
} break;
default:
TRACE_BT("LocalDeviceImpl: Command Status not handled\n");
break;
@@ -1376,6 +1382,34 @@ LocalDeviceImpl::SimplePairingComplete(struct hci_ev_simple_pairing_complete* ev
ClearWantedEvent(request);
}
void
LocalDeviceImpl::AuthComplete(struct hci_ev_auth_complete* eventData, BMessage* request)
{
int16 handle = B_LENDIAN_TO_HOST_INT16(eventData->handle);
int8 status = eventData->status;
if (status == BT_OK) {
TRACE_BT("LocalDeviceImpl: Authentication Successful for handle %d\n", handle);
} else {
TRACE_BT("LocalDeviceImpl: Authentication Failed for handle %d with status 0x%02x\n",
handle, status);
}
if (request != NULL) {
BMessage reply;
reply.AddInt8("status", status);
reply.AddInt16("handle", handle);
request->SendReply(&reply);
ClearWantedEvent(request);
} else {
TRACE_BT("LocalDeviceImpl: Auth Complete received but no local request was waiting.\n");
}
}
#if 0
#pragma mark - Request Methods -
#endif
+1
View File
@@ -84,6 +84,7 @@ private:
void UserConfirmationRequest(struct hci_ev_user_confirmation_request* event, BMessage* request);
void SimplePairingComplete(struct hci_ev_simple_pairing_complete* event,
BMessage* request);
void AuthComplete(struct hci_ev_auth_complete* eventData, BMessage* request);
};
#endif