Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ash decoder when running late on EZSP/ASH frames input #52

Open
lionelains opened this issue Mar 9, 2020 · 5 comments
Open

Fix ash decoder when running late on EZSP/ASH frames input #52

lionelains opened this issue Mar 9, 2020 · 5 comments
Labels
bug Something isn't working

Comments

@lionelains
Copy link
Contributor

ASH decoder fails to decode properly.
To reproduce this, run the lib in a debugger, break on the initialization of the lib (anywhere between start() and the run state).
If more than GP report is received, you will get an ASH decoding error.
This is either because multiple frames are sent to the decoder at once (low probability) or because frames are not acknowledges by the lib and thus retransmitted several times by the NCP (more likely).

CAsh::decode ERROR
Reading from serial port: 66 ee fe c6 63 2b e1 76 a0 24 14 c3 dc 6b 8f ff ee 16 dd d7 6d 8c 46 02 75 e1 9e 39 7e 26 7f b1 57 54 ef 6a 61 3f 94 72 25 fe 55 aa 49 c8 4e e2 a9 ec ce 66 ed fe c6 63 2b b8 de ec 5b 14 c3 dc
Writing to serial port: 82 50 3a 7e
Asynchronous received EZSP message
CLibEzspMain::handleEzspRxMessage EZSP_GPEP_INCOMING_MESSAGE_HANDLER
Searching source ID 0x540038
... not found
I know no key for this source ID
EZSP_GPEP_INCOMING_MESSAGE_HANDLER status : UNDOCUMENTED_UNKNOWN_KEY_FOR_SOURCE_ID, link : d4, sequence number : 65, gp address : CGpFrame: { [link_value: 0xd4][sequence_number: 0x65][source_id: 00540038][security: 2][key_type: 1][auto_commissioning: N][rx_after_tx: Y][security_frame_counter: 00000365][command_id: a2][mic: 839f081d][proxy_table_entry: 0xff][payload:02 04 00 00 29 cd 08 05 04 00 00 21 dc 0d] }
Reading from serial port: 6b 8f ff ee 17 dd d7 6d 8c 46 02 70 e1 c4 c8 7e 36 7f b1 57 54 ef 6a 66 3e 94 72 25 fe 55 aa 49 c8 4e e2 a9 ec ce 66 ec fe c6 63 2b 62 62 bc 02 14 c3 dc 6b 8f ff ee 15 dd d7 6d 8c 46 02 42 e1
Writing to serial port: 83 40 1b 7e
Asynchronous received EZSP message
CLibEzspMain::handleEzspRxMessage EZSP_GPEP_INCOMING_MESSAGE_HANDLER
Searching source ID 0x540038
... not found
I know no key for this source ID
EZSP_GPEP_INCOMING_MESSAGE_HANDLER status : UNDOCUMENTED_UNKNOWN_KEY_FOR_SOURCE_ID, link : d3, sequence number : 66, gp address : CGpFrame: { [link_value: 0xd3][sequence_number: 0x66][source_id: 00540038][security: 2][key_type: 1][auto_commissioning: N][rx_after_tx: Y][security_frame_counter: 00000366][command_id: a2][mic: fcd3a044][proxy_table_entry: 0xff][payload:02 04 00 00 29 cc 08 05 04 00 00 21 d9 0d] }
Reading from serial port: 17 d7 7e 46 7f b1 57 54 ef 6a 66 31 94 72 25 fe 55 aa 49 c8 4e e2 a9 ec ce 66 e3 fe c6 63 2b ce a2 26 fd 14 c3 dc 6b 8f ff ee 14 dd d7 6d 8c 46 02 bb e2 3c 2b 7e c2 02 51 a8 bd 7e c2 02 51 a8
Writing to serial port: 84 30 fc 7e
Asynchronous received EZSP message
CLibEzspMain::handleEzspRxMessage EZSP_GPEP_INCOMING_MESSAGE_HANDLER
Searching source ID 0x540038
... not found
I know no key for this source ID
EZSP_GPEP_INCOMING_MESSAGE_HANDLER status : UNDOCUMENTED_UNKNOWN_KEY_FOR_SOURCE_ID, link : d4, sequence number : 67, gp address : CGpFrame: { [link_value: 0xd4][sequence_number: 0x67][source_id: 00540038][security: 2][key_type: 1][auto_commissioning: N][rx_after_tx: Y][security_frame_counter: 00000367][command_id: a2][mic: a5831c9e][proxy_table_entry: 0xff][payload:02 04 00 00 29 ce 08 05 04 00 00 21 eb 0d] }
Writing to serial port: 85 20 dd 7e
Asynchronous received EZSP message
CLibEzspMain::handleEzspRxMessage EZSP_GPEP_INCOMING_MESSAGE_HANDLER
Searching source ID 0x540038
... not found
I know no key for this source ID
EZSP_GPEP_INCOMING_MESSAGE_HANDLER status : UNDOCUMENTED_UNKNOWN_KEY_FOR_SOURCE_ID, link : d4, sequence number : 68, gp address : CGpFrame: { [link_value: 0xd4][sequence_number: 0x68][source_id: 00540038][security: 2][key_type: 1][auto_commissioning: N][rx_after_tx: Y][security_frame_counter: 00000368][command_id: a2][mic: 5a19dc32][proxy_table_entry: 0xff][payload:02 04 00 00 29 cf 08 05 04 00 00 21 12 0e] }
CAsh::decode ERROR
Reading from serial port: bd 7e c2 02 51 a8 bd 7e c2 02 51 a8 bd 7e c2 02 51 a8 bd 7e c2 02 51 a8 bd 7e
CAsh::decode ERROR
CAsh::decode ERROR
CAsh::decode ERROR
CAsh::decode ERROR
CAsh::decode ERROR
Reading from serial port: c2 02 51 a8 bd 7e c2 02 51 a8 bd 7e c2 02 51 a8 bd 7e
CAsh::decode ERROR
CAsh::decode ERROR
CAsh::decode ERROR
ASH timeout while connected
@lionelains lionelains added the bug Something isn't working label May 26, 2020
@lionelains
Copy link
Contributor Author

Reproduced after refactoring ASH decoder in 228d764
We can trigger this issue when getting an asynchronous GP report while inside the EZSP command/response sequence of the library startup.
We then get an error like:

EZSP_GP_PROXY_TABLE_PROCESS_GP_PAIRING
Received a wrong ack num: 2, expected: 3
Asynchronous received EZSP message
CLibEzspMain::handleEzspRxMessage EZSP_GPEP_INCOMING_MESSAGE_HANDLER

@lionelains
Copy link
Contributor Author

Maybe related to issue #62

@lionelains
Copy link
Contributor Author

Also implies duplicated reports.
Scenario to reproduce this:

  • run mainEzspTest in gdb with a correct sensor key+sourceID
  • interrupt the program (Ctrl+C)
  • force a report from the sensor
  • wait a few seconds
  • resume the program execution (issue continue on gdb)

The library runs late on the EZSP sequence (does not ack the report).
Thus the NCP retransmits the sensor measurement more than once.
The library then recovers all late messages, but displays several measurements (also displaying a message "Multiple EZSP payloads extraction from one ASH stream" instead of discarding duplicates)

@lionelains
Copy link
Contributor Author

We can also reproduce the "wrong ack num" message by simultaneously releasing the button of two known sensors during a MSP channel switch procedure.
Start the procedure on 2 sensors, wait until the LED turns steady green on both sensors, and release both buttons at the same time.

@lionelains
Copy link
Contributor Author

Both scenarios are linked to the same issue: a loss of sync for ASH frames between the host and NCP (either on ezsp sequence number or on lost bytes).
If we loose bytes, we will have a AshCodec::decode ERROR log (a procedure to reproduce this is detailed here).

When this occurs, if we try to send a new EZSP command to the NCP, we will get an "ASH timeout while connected" log.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant