Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ce5a151e authored by Myles Watson's avatar Myles Watson Committed by Automerger Merge Worker
Browse files

Merge "RootCanal: Handle IoCapabilityRequestNegativeReply" am: 2e6eb82d am: 6e3efdc4

parents 52ea93fa 6e3efdc4
Loading
Loading
Loading
Loading
+112 −56
Original line number Diff line number Diff line
@@ -329,7 +329,14 @@ const PASSKEY_ENTRY_REPEAT_NUMBER: usize = 20;
pub async fn initiate(ctx: &impl Context) -> Result<(), ()> {
    let initiator = {
        ctx.send_hci_event(hci::IoCapabilityRequestBuilder { bd_addr: ctx.peer_address() }.build());
        let reply = ctx.receive_hci_command::<hci::IoCapabilityRequestReplyPacket>().await;
        match ctx
                .receive_hci_command::<Either<
                    hci::IoCapabilityRequestReplyPacket,
                    hci::IoCapabilityRequestNegativeReplyPacket,
                >>()
                .await
            {
                Either::Left(reply) => {
                    ctx.send_hci_event(
                        hci::IoCapabilityRequestReplyCompleteBuilder {
                            num_hci_command_packets,
@@ -338,7 +345,6 @@ pub async fn initiate(ctx: &impl Context) -> Result<(), ()> {
                        }
                        .build(),
                    );

                    ctx.send_lmp_packet(
                        lmp::IoCapabilityReqBuilder {
                            transaction_id: 0,
@@ -351,12 +357,31 @@ pub async fn initiate(ctx: &impl Context) -> Result<(), ()> {
                        }
                        .build(),
                    );

                    AuthenticationParams {
                        io_capability: reply.get_io_capability(),
                        oob_data_present: reply.get_oob_present(),
                        authentication_requirements: reply.get_authentication_requirements(),
                    }
                }
                Either::Right(_) => {
                    ctx.send_hci_event(
                        hci::IoCapabilityRequestNegativeReplyCompleteBuilder {
                            num_hci_command_packets,
                            status : hci::ErrorCode::Success,
                            bd_addr: ctx.peer_address(),
                        }
                        .build(),
                    );
                    ctx.send_hci_event(
                        hci::SimplePairingCompleteBuilder {
                            status : hci::ErrorCode::AuthenticationFailure,
                            bd_addr: ctx.peer_address(),
                        }
                        .build(),
                    );
                    return Err(());
                }
            }
    };
    let responder = {
        let response = ctx.receive_lmp_packet::<lmp::IoCapabilityResPacket>().await;
@@ -534,7 +559,14 @@ pub async fn respond(ctx: &impl Context, request: lmp::IoCapabilityReqPacket) ->

    let responder = {
        ctx.send_hci_event(hci::IoCapabilityRequestBuilder { bd_addr: ctx.peer_address() }.build());
        let reply = ctx.receive_hci_command::<hci::IoCapabilityRequestReplyPacket>().await;
        match ctx
                .receive_hci_command::<Either<
                    hci::IoCapabilityRequestReplyPacket,
                    hci::IoCapabilityRequestNegativeReplyPacket,
                >>()
                .await
            {
                Either::Left(reply) => {
                    ctx.send_hci_event(
                        hci::IoCapabilityRequestReplyCompleteBuilder {
                            num_hci_command_packets,
@@ -543,7 +575,6 @@ pub async fn respond(ctx: &impl Context, request: lmp::IoCapabilityReqPacket) ->
                        }
                        .build(),
                    );

                    ctx.send_lmp_packet(
                        lmp::IoCapabilityResBuilder {
                            transaction_id: 0,
@@ -561,6 +592,34 @@ pub async fn respond(ctx: &impl Context, request: lmp::IoCapabilityReqPacket) ->
                        oob_data_present: reply.get_oob_present(),
                        authentication_requirements: reply.get_authentication_requirements(),
                    }
                }
                Either::Right(reply) => {
                    ctx.send_hci_event(
                        hci::IoCapabilityRequestNegativeReplyCompleteBuilder {
                            num_hci_command_packets,
                            status: hci::ErrorCode::Success,
                            bd_addr: ctx.peer_address(),
                        }
                        .build(),
                    );
                    ctx.send_lmp_packet(
                        lmp::NotAcceptedExtBuilder {
                            transaction_id: 0,
                            error_code: reply.get_reason().to_u8().unwrap(),
                            not_accepted_opcode: lmp::ExtendedOpcode::IoCapabilityReq,
                        }
                        .build(),
                    );
                    ctx.send_hci_event(
                        hci::SimplePairingCompleteBuilder {
                            status: hci::ErrorCode::AuthenticationFailure,
                            bd_addr: reply.get_bd_addr(),
                        }
                        .build(),
                    );
                    return Err(());
                }
            }
    };

    // Public Key Exchange
@@ -929,7 +988,6 @@ mod tests {
    }

    #[test]
    #[should_panic] // TODO: make the test pass
    fn secure_simple_pairing_failed_responder() {
        let context = TestContext::new();
        let procedure = respond;
@@ -938,7 +996,6 @@ mod tests {
    }

    #[test]
    #[should_panic] // TODO: make the test pass
    fn host_rejects_secure_simple_pairing_initiator() {
        let context = TestContext::new();
        let procedure = initiate;
@@ -947,7 +1004,6 @@ mod tests {
    }

    #[test]
    #[should_panic] // TODO: make the test pass
    fn host_rejects_secure_simple_pairing_responder() {
        let context = TestContext::new();
        let procedure = respond;