Loading tools/rootcanal/lmp/src/procedure/secure_simple_pairing.rs +112 −56 Original line number Diff line number Diff line Loading @@ -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, Loading @@ -338,7 +345,6 @@ pub async fn initiate(ctx: &impl Context) -> Result<(), ()> { } .build(), ); ctx.send_lmp_packet( lmp::IoCapabilityReqBuilder { transaction_id: 0, Loading @@ -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; Loading Loading @@ -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, Loading @@ -543,7 +575,6 @@ pub async fn respond(ctx: &impl Context, request: lmp::IoCapabilityReqPacket) -> } .build(), ); ctx.send_lmp_packet( lmp::IoCapabilityResBuilder { transaction_id: 0, Loading @@ -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 Loading Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading Loading
tools/rootcanal/lmp/src/procedure/secure_simple_pairing.rs +112 −56 Original line number Diff line number Diff line Loading @@ -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, Loading @@ -338,7 +345,6 @@ pub async fn initiate(ctx: &impl Context) -> Result<(), ()> { } .build(), ); ctx.send_lmp_packet( lmp::IoCapabilityReqBuilder { transaction_id: 0, Loading @@ -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; Loading Loading @@ -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, Loading @@ -543,7 +575,6 @@ pub async fn respond(ctx: &impl Context, request: lmp::IoCapabilityReqPacket) -> } .build(), ); ctx.send_lmp_packet( lmp::IoCapabilityResBuilder { transaction_id: 0, Loading @@ -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 Loading Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading