PetteriAimonen opened a new pull request #3163:
URL: https://github.com/apache/incubator-nuttx/pull/3163


   ## Summary
   
   Sometimes Windows would send RNDIS_KEEPALIVE_MSG and RNDIS_QUERY_MSG close 
to each other. This would cause the latter command to overwrite the reply for 
the prior command. This in turn will cause Windows to drop the connection after 
a 20 second timeout.
       
   Easy way to reproduce the issue is to open the Windows "Adapter Status" 
dialog that shows the realtime TX/RX byte counts. This causes multiple 
RNDIS_QUERY_MSGs per second, and the connection will drop in less than an hour.
       
   This commit fixes this issue, and other potential race conditions (such as 
USB descriptor read in middle on RNDIS query) by using a separate queue for the 
reply packets.
   
   Example USB trace:
   
   <pre>
   13:21:14.104859 | usb_packet-1: SETUP ADDR 1 EP 0                     <---- 
Host starts 04 RNDIS_QUERY_MSG request
   13:21:14.104862 | usb_packet-1: DATA0 [ 21 00 00 00 00 00 4C 00 ]
   13:21:14.104871 | usb_packet-1: ACK
   13:21:14.104878 | usb_packet-1: IN ADDR 1 EP 1
   13:21:14.104881 | usb_packet-1: NAK
                   | Previous two lines repeated 170 times
   13:21:14.105847 | usb_packet-1: SOF 750
   13:21:14.105850 | usb_packet-1: IN ADDR 1 EP 3
   13:21:14.105853 | usb_packet-1: NAK
   13:21:14.105859 | usb_packet-1: OUT ADDR 1 EP 0
   13:21:14.105863 | usb_packet-1: DATA1 [ 04 00 00 00 4C 00 00 00 BC 03 00 00 
02 01 02 00 30 00 00 00 14 00 00 00 00 00 00 00 AB 01 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ]
   13:21:14.105908 | usb_packet-1: NAK
   13:21:14.105916 | usb_packet-1: IN ADDR 1 EP 1
                   | Previous two lines repeated 163 times
   13:21:14.106847 | usb_packet-1: SOF 751
   13:21:14.106850 | usb_packet-1: IN ADDR 1 EP 3
   13:21:14.106853 | usb_packet-1: NAK
   13:21:14.106860 | usb_packet-1: OUT ADDR 1 EP 0
   13:21:14.106863 | usb_packet-1: DATA1 [ 04 00 00 00 4C 00 00 00 BC 03 00 00 
02 01 02 00 30 00 00 00 14 00 00 00 00 00 00 00 AB 01 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ]
   13:21:14.106909 | usb_packet-1: ACK           <---------- 04 RNDIS_QUERY_MSG 
first packet received
   13:21:14.106916 | usb_packet-1: IN ADDR 1 EP 1
   13:21:14.106919 | usb_packet-1: NAK
                   | Previous two lines repeated 162 times
   13:21:14.107847 | usb_packet-1: SOF 752
   13:21:14.107850 | usb_packet-1: IN ADDR 1 EP 3
   13:21:14.107854 | usb_packet-1: DATA0 [ 01 00 00 00 00 00 00 00 ]
   13:21:14.107863 | usb_packet-1: ACK                               <------- 
Interrupt endpoint notification that command result is available.
   13:21:14.107868 | usb_packet-1: OUT ADDR 1 EP 0
   13:21:14.107871 | usb_packet-1: DATA0 [ 00 00 00 00 00 00 00 00 00 00 00 00 ]
   13:21:14.107883 | usb_packet-1: ACK                             <---- 
Delayed last 12 bytes (separate bug #3162)
   13:21:14.107890 | usb_packet-1: IN ADDR 1 EP 1
   13:21:14.107893 | usb_packet-1: NAK
                   | Previous two lines repeated 168 times
   ....
   13:21:14.109848 | usb_packet-1: SOF 754
   13:21:14.109851 | usb_packet-1: IN ADDR 1 EP 3
   13:21:14.109854 | usb_packet-1: NAK
   13:21:14.109860 | usb_packet-1: SETUP ADDR 1 EP 0          <---- Host starts 
08 RNDIS_KEEPALIVE_MSG
   13:21:14.109863 | usb_packet-1: DATA0 [ 21 00 00 00 00 00 0C 00 ]
   13:21:14.109872 | usb_packet-1: ACK
   13:21:14.109879 | usb_packet-1: IN ADDR 1 EP 1
   13:21:14.109883 | usb_packet-1: NAK
                   | Previous two lines repeated 170 times
   13:21:14.110848 | usb_packet-1: SOF 755
   13:21:14.110851 | usb_packet-1: IN ADDR 1 EP 3
   13:21:14.110855 | usb_packet-1: NAK
   13:21:14.110861 | usb_packet-1: OUT ADDR 1 EP 0
   13:21:14.110864 | usb_packet-1: DATA1 [ 08 00 00 00 0C 00 00 00 BD 03 00 00 ]
   13:21:14.110875 | usb_packet-1: NAK
   13:21:14.110882 | usb_packet-1: IN ADDR 1 EP 1
                   | Previous two lines repeated 171 times
   13:21:14.111848 | usb_packet-1: SOF 756
   13:21:14.111852 | usb_packet-1: IN ADDR 1 EP 3
   13:21:14.111855 | usb_packet-1: NAK
   13:21:14.111861 | usb_packet-1: OUT ADDR 1 EP 0
   13:21:14.111864 | usb_packet-1: DATA1 [ 08 00 00 00 0C 00 00 00 BD 03 00 00 ]
   13:21:14.111876 | usb_packet-1: ACK                              <--- 
RNDIS_KEEPALIVE_MSG complete
   13:21:14.111883 | usb_packet-1: IN ADDR 1 EP 1
   13:21:14.111886 | usb_packet-1: NAK
                   | Previous two lines repeated 170 times
   13:21:14.112849 | usb_packet-1: SOF 757
   13:21:14.112852 | usb_packet-1: IN ADDR 1 EP 3
   13:21:14.112855 | usb_packet-1: DATA1 [ 01 00 00 00 00 00 00 00 ]
   13:21:14.112864 | usb_packet-1: ACK                            <--- 
Notification of command result available
   13:21:14.112869 | usb_packet-1: IN ADDR 1 EP 0
   13:21:14.112872 | usb_packet-1: DATA1 [ ]
   13:21:14.112875 | usb_packet-1: ACK
   13:21:14.112882 | usb_packet-1: IN ADDR 1 EP 1
   13:21:14.112885 | usb_packet-1: NAK
   ...
   13:21:14.116861 | usb_packet-1: IN ADDR 1 EP 0
   13:21:14.116865 | usb_packet-1: DATA1 [ 08 00 00 80 10 00 00 00 BD 03 00 00 
00 00 00 00 ]
   13:21:14.116879 | usb_packet-1: ACK                          <---- Got 08 
RNDIS_KEEPALIVE_MSG response, the earlier 04 has been overwritten.
   </pre>
   
   ## Impact
   
   This improves reliability of RNDIS communications. In our use case, the 
problem only occurred once in several days unless the Network Adapter Status 
dialog was open. So the race condition is quite rare in normal usage.
   
   ## Testing
   
   Tested on custom STM32F4 board with USB RNDIS driver.
   
   The bug can be easiest reproduced by opening the Windows network adapter 
statistics
   window, which causes concurrent RNDIS requests. Note that on STM32 #3162 
also occurs
   in this situation.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to