@@ -348,65 +348,64 @@ async fn run_exchange_flow<C: Crypto>(
348348 info ! ( "PBKDFParamRequest sent, waiting for response..." ) ;
349349
350350 // Step 3: Wait for response with a timeout
351- let ( result, should_ack) = {
352- let mut should_ack = false ;
353- let mut recv_fut = core:: pin:: pin!( exchange. recv( ) ) ;
354- let mut timeout = core:: pin:: pin!( Timer :: after( embassy_time:: Duration :: from_secs( 10 ) ) ) ;
355-
356- let result = match select ( & mut recv_fut, & mut timeout) . await {
357- Either :: First ( result) => {
358- let rx = result?;
359- let meta = rx. meta ( ) ;
360-
361- info ! (
362- "Received response: proto_id=0x{:04x}, opcode=0x{:02x}" ,
363- meta. proto_id, meta. proto_opcode
364- ) ;
365-
366- if meta. proto_id == PROTO_ID_SECURE_CHANNEL
367- && meta. proto_opcode == OpCode :: PBKDFParamResponse as u8
368- {
369- should_ack = true ;
370- info ! ( "Got PBKDFParamResponse - exchange round-trip successful!" ) ;
371- Ok ( ( ) )
372- } else if meta. proto_id == PROTO_ID_SECURE_CHANNEL
373- && meta. proto_opcode == OpCode :: StatusReport as u8
374- {
375- // A status report is also acceptable - it means the device received
376- // our message and responded (e.g. Busy, or commissioning window not open)
377- let mut rb = ReadBuf :: new ( rx. payload ( ) ) ;
378- match StatusReport :: read ( & mut rb) {
379- Ok ( report) => {
380- info ! (
381- "Got StatusReport - general_code={:?}, proto_id=0x{:04x}, proto_code=0x{:04x}" ,
382- report. general_code, report. proto_id, report. proto_code
383- ) ;
384- }
385- Err ( e) => {
386- warn ! ( "Failed to parse StatusReport: {e:?}" ) ;
387- }
388- }
389- should_ack = true ;
390- info ! ( "Exchange round-trip successful (device responded with status)" ) ;
391- Ok ( ( ) )
392- } else {
351+ let rx = match select (
352+ core:: pin:: pin!( exchange. recv( ) ) ,
353+ core:: pin:: pin!( Timer :: after( embassy_time:: Duration :: from_secs( 10 ) ) ) ,
354+ )
355+ . await
356+ {
357+ Either :: First ( Ok ( rx) ) => rx,
358+ Either :: First ( Err ( e) ) => return Err ( e) ,
359+ Either :: Second ( _) => {
360+ warn ! ( "Timeout waiting for response" ) ;
361+ return Err ( rs_matter:: error:: ErrorCode :: RxTimeout . into ( ) ) ;
362+ }
363+ } ;
364+
365+ let result = {
366+ let meta = rx. meta ( ) ;
367+ info ! (
368+ "Received response: proto_id=0x{:04x}, opcode=0x{:02x}" ,
369+ meta. proto_id, meta. proto_opcode
370+ ) ;
371+
372+ if meta. proto_id == PROTO_ID_SECURE_CHANNEL
373+ && meta. proto_opcode == OpCode :: PBKDFParamResponse as u8
374+ {
375+ info ! ( "Got PBKDFParamResponse - exchange round-trip successful!" ) ;
376+ Ok ( ( ) )
377+ } else if meta. proto_id == PROTO_ID_SECURE_CHANNEL
378+ && meta. proto_opcode == OpCode :: StatusReport as u8
379+ {
380+ // A status report is also acceptable - it means the device received
381+ // our message and responded (e.g. Busy, or commissioning window not open)
382+ let mut rb = ReadBuf :: new ( rx. payload ( ) ) ;
383+ match StatusReport :: read ( & mut rb) {
384+ Ok ( report) => {
393385 info ! (
394- "Unexpected response opcode: proto =0x{:04x} op =0x{:02x }" ,
395- meta . proto_id, meta . proto_opcode
386+ "Got StatusReport - general_code={:?}, proto_id =0x{:04x}, proto_code =0x{:04x }" ,
387+ report . general_code , report . proto_id, report . proto_code
396388 ) ;
397- Err ( rs_matter:: error:: ErrorCode :: InvalidData . into ( ) )
389+ }
390+ Err ( e) => {
391+ warn ! ( "Failed to parse StatusReport: {e:?}" ) ;
398392 }
399393 }
400- Either :: Second ( _) => {
401- warn ! ( "Timeout waiting for response" ) ;
402- Err ( rs_matter:: error:: ErrorCode :: RxTimeout . into ( ) )
403- }
404- } ;
405-
406- ( result, should_ack)
394+ info ! ( "Exchange round-trip successful (device responded with status)" ) ;
395+ Ok ( ( ) )
396+ } else {
397+ info ! (
398+ "Unexpected response opcode: proto=0x{:04x} op=0x{:02x}" ,
399+ meta. proto_id, meta. proto_opcode
400+ ) ;
401+ Err ( rs_matter:: error:: ErrorCode :: InvalidData . into ( ) )
402+ }
407403 } ;
408404
409- if should_ack {
405+ // Release rx's borrow on `exchange` so we can call `acknowledge()` below
406+ drop ( rx) ;
407+
408+ if result. is_ok ( ) {
410409 // Send standalone ACK so the responder stops retransmitting
411410 exchange. acknowledge ( ) . await ?;
412411 }
0 commit comments