@@ -253,7 +253,7 @@ static void xmit_put_ntb_into_free_list(xmit_ntb_t *free_ntb)
253253 return ;
254254 }
255255 }
256- ERROR_OUT ("xmit_put_ntb_into_free_list - no entry in free list\n" ); // this should not happen
256+ ERROR_OUT ("(EE) xmit_put_ntb_into_free_list - no entry in free list\n" ); // this should not happen
257257} // xmit_put_ntb_into_free_list
258258
259259
@@ -282,15 +282,15 @@ static void xmit_put_ntb_into_ready_list(xmit_ntb_t *ready_ntb)
282282 * Put a filled NTB into the ready list
283283 */
284284{
285- INFO_OUT ("xmit_put_ntb_into_ready_list(%p) %d\n" , ready_ntb , ready_ntb -> len );
285+ INFO_OUT ("xmit_put_ntb_into_ready_list(%p) %d\n" , ready_ntb , ready_ntb -> nth . wBlockLength );
286286
287287 for (int i = 0 ; i < XMIT_NTB_N ; ++ i ) {
288288 if (ncm_interface .xmit_ready_ntb [i ] == NULL ) {
289289 ncm_interface .xmit_ready_ntb [i ] = ready_ntb ;
290290 return ;
291291 }
292292 }
293- ERROR_OUT ("xmit_put_ntb_into_ready_list: ready list full\n" ); // this should not happen
293+ ERROR_OUT ("(EE) xmit_put_ntb_into_ready_list: ready list full\n" ); // this should not happen
294294} // xmit_put_ntb_into_ready_list
295295
296296
@@ -305,6 +305,7 @@ static xmit_ntb_t *xmit_get_next_ready_ntb(void)
305305
306306 r = ncm_interface .xmit_ready_ntb [0 ];
307307 memmove (ncm_interface .xmit_ready_ntb + 0 , ncm_interface .xmit_ready_ntb + 1 , sizeof (ncm_interface .xmit_ready_ntb ) - sizeof (ncm_interface .xmit_ready_ntb [0 ]));
308+ ncm_interface .xmit_ready_ntb [XMIT_NTB_N - 1 ] = NULL ;
308309
309310 DEBUG_OUT ("recv_get_next_ready_ntb: %p\n" , r );
310311 return r ;
@@ -356,7 +357,7 @@ static void xmit_start_if_possible(uint8_t rhport)
356357 return ;
357358 }
358359 if (ncm_interface .itf_data_alt != 1 ) {
359- ERROR_OUT (" !xmit_start_if_possible 2\n" );
360+ ERROR_OUT ("(II) !xmit_start_if_possible 2\n" );
360361 return ;
361362 }
362363 if (usbd_edpt_busy (rhport , ncm_interface .ep_in )) {
@@ -374,9 +375,9 @@ static void xmit_start_if_possible(uint8_t rhport)
374375 ncm_interface .xmit_glue_ntb = NULL ;
375376 }
376377
377- #if DEBUG_OUT_ENABLED
378+ #ifdef DEBUG_OUT_ENABLED
378379 {
379- uint16_t len = ncm_interface .xmit_tinyusb_ntb -> ntb . nth .wBlockLength ;
380+ uint16_t len = ncm_interface .xmit_tinyusb_ntb -> nth .wBlockLength ;
380381 DEBUG_OUT (" %d\n" , len );
381382 for (int i = 0 ; i < len ; ++ i ) {
382383 DEBUG_OUT (" %02x" , ncm_interface .xmit_tinyusb_ntb -> data [i ]);
@@ -386,7 +387,7 @@ static void xmit_start_if_possible(uint8_t rhport)
386387#endif
387388
388389 if (ncm_interface .xmit_glue_ntb_datagram_ndx != 1 ) {
389- DEBUG_OUT (">> %d %d\n" , ncm_interface .xmit_tinyusb_ntb -> len , ncm_interface .xmit_glue_ntb_datagram_ndx );
390+ DEBUG_OUT (">> %d %d\n" , ncm_interface .xmit_tinyusb_ntb -> nth . wBlockLength , ncm_interface .xmit_glue_ntb_datagram_ndx );
390391 }
391392
392393 // Kick off an endpoint transfer
@@ -491,6 +492,7 @@ static recv_ntb_t *recv_get_next_ready_ntb(void)
491492
492493 r = ncm_interface .recv_ready_ntb [0 ];
493494 memmove (ncm_interface .recv_ready_ntb + 0 , ncm_interface .recv_ready_ntb + 1 , sizeof (ncm_interface .recv_ready_ntb ) - sizeof (ncm_interface .recv_ready_ntb [0 ]));
495+ ncm_interface .recv_ready_ntb [RECV_NTB_N - 1 ] = NULL ;
494496
495497 DEBUG_OUT ("recv_get_next_ready_ntb: %p\n" , r );
496498 return r ;
@@ -511,7 +513,7 @@ static void recv_put_ntb_into_free_list(recv_ntb_t *free_ntb)
511513 return ;
512514 }
513515 }
514- ERROR_OUT ("recv_put_ntb_into_free_list - no entry in free list\n" ); // this should not happen
516+ ERROR_OUT ("(EE) recv_put_ntb_into_free_list - no entry in free list\n" ); // this should not happen
515517} // recv_put_ntb_into_free_list
516518
517519
@@ -522,15 +524,15 @@ static void recv_put_ntb_into_ready_list(recv_ntb_t *ready_ntb)
522524 * put this buffer into the waiting list and free the receive logic.
523525 */
524526{
525- DEBUG_OUT ("recv_put_ntb_into_ready_list(%p) %d\n" , ready_ntb , ready_ntb -> len );
527+ DEBUG_OUT ("recv_put_ntb_into_ready_list(%p) %d\n" , ready_ntb , ready_ntb -> nth . wBlockLength );
526528
527529 for (int i = 0 ; i < RECV_NTB_N ; ++ i ) {
528530 if (ncm_interface .recv_ready_ntb [i ] == NULL ) {
529531 ncm_interface .recv_ready_ntb [i ] = ready_ntb ;
530532 return ;
531533 }
532534 }
533- ERROR_OUT ("recv_put_ntb_into_ready_list: ready list full\n" ); // this should not happen
535+ ERROR_OUT ("(EE) recv_put_ntb_into_ready_list: ready list full\n" ); // this should not happen
534536} // recv_put_ntb_into_ready_list
535537
536538
@@ -587,27 +589,27 @@ static bool recv_validate_datagram(const recv_ntb_t *ntb, uint16_t len)
587589 //
588590 if (nth16 -> wHeaderLength != sizeof (nth16_t ))
589591 {
590- ERROR_OUT (" ill nth16 length: %d\n" , nth16 -> wHeaderLength );
592+ ERROR_OUT ("(EE) ill nth16 length: %d\n" , nth16 -> wHeaderLength );
591593 return false;
592594 }
593595 if (nth16 -> dwSignature != NTH16_SIGNATURE ) {
594- ERROR_OUT (" ill signature: 0x%08x\n" , (unsigned )nth16 -> dwSignature );
596+ ERROR_OUT ("(EE) ill signature: 0x%08x\n" , (unsigned )nth16 -> dwSignature );
595597 return false;
596598 }
597599 if (len < sizeof (nth16_t ) + sizeof (ndp16_t ) + 2 * sizeof (ndp16_datagram_t )) {
598- ERROR_OUT (" ill min len: %d\n" , len );
600+ ERROR_OUT ("(EE) ill min len: %d\n" , len );
599601 return false;
600602 }
601603 if (nth16 -> wBlockLength > len ) {
602- ERROR_OUT (" ill block length: %d > %d\n" , nth16 -> wBlockLength , len );
604+ ERROR_OUT ("(EE) ill block length: %d > %d\n" , nth16 -> wBlockLength , len );
603605 return false;
604606 }
605607 if (nth16 -> wBlockLength > CFG_TUD_NCM_OUT_NTB_MAX_SIZE ) {
606- ERROR_OUT (" ill block length2: %d > %d\n" , nth16 -> wBlockLength , CFG_TUD_NCM_OUT_NTB_MAX_SIZE );
608+ ERROR_OUT ("(EE) ill block length2: %d > %d\n" , nth16 -> wBlockLength , CFG_TUD_NCM_OUT_NTB_MAX_SIZE );
607609 return false;
608610 }
609611 if (nth16 -> wNdpIndex < sizeof (nth16 ) || nth16 -> wNdpIndex > len - (sizeof (ndp16_t ) + 2 * sizeof (ndp16_datagram_t ))) {
610- ERROR_OUT (" ill position of first ndp: %d (%d)\n" , nth16 -> wNdpIndex , len );
612+ ERROR_OUT ("(EE) ill position of first ndp: %d (%d)\n" , nth16 -> wNdpIndex , len );
611613 return false;
612614 }
613615
@@ -617,15 +619,15 @@ static bool recv_validate_datagram(const recv_ntb_t *ntb, uint16_t len)
617619 const ndp16_t * ndp16 = (ndp16_t * )(ntb -> data + nth16 -> wNdpIndex );
618620
619621 if (ndp16 -> wLength < sizeof (ndp16_t ) + 2 * sizeof (ndp16_datagram_t )) {
620- ERROR_OUT (" ill ndp16 length: %d\n" , ndp16 -> wLength );
622+ ERROR_OUT ("(EE) ill ndp16 length: %d\n" , ndp16 -> wLength );
621623 return false;
622624 }
623625 if (ndp16 -> dwSignature != NDP16_SIGNATURE_NCM0 && ndp16 -> dwSignature != NDP16_SIGNATURE_NCM1 ) {
624- ERROR_OUT (" ill signature: 0x%08x\n" , (unsigned )ndp16 -> dwSignature );
626+ ERROR_OUT ("(EE) ill signature: 0x%08x\n" , (unsigned )ndp16 -> dwSignature );
625627 return false;
626628 }
627629 if (ndp16 -> wNextNdpIndex != 0 ) {
628- ERROR_OUT (" cannot handle wNextNdpIndex!=0 (%d)\n" , ndp16 -> wNextNdpIndex );
630+ ERROR_OUT ("(EE) cannot handle wNextNdpIndex!=0 (%d)\n" , ndp16 -> wNextNdpIndex );
629631 return false;
630632 }
631633
@@ -635,7 +637,7 @@ static bool recv_validate_datagram(const recv_ntb_t *ntb, uint16_t len)
635637
636638 if (max_ndx > 2 ) {
637639 // number of datagrams in NTB > 1
638- INFO_OUT ("<< %d (%d)\n" , max_ndx - 1 , ntb -> len );
640+ INFO_OUT ("<< %d (%d)\n" , max_ndx - 1 , ntb -> nth . wBlockLength );
639641 }
640642 if (ndp16_datagram [max_ndx - 1 ].wDatagramIndex != 0 || ndp16_datagram [max_ndx - 1 ].wDatagramLength != 0 ) {
641643 INFO_OUT (" max_ndx != 0\n" );
@@ -644,11 +646,11 @@ static bool recv_validate_datagram(const recv_ntb_t *ntb, uint16_t len)
644646 while (ndp16_datagram [ndx ].wDatagramIndex != 0 && ndp16_datagram [ndx ].wDatagramLength != 0 ) {
645647 DEBUG_OUT (" << %d %d\n" , ndp16_datagram [ndx ].wDatagramIndex , ndp16_datagram [ndx ].wDatagramLength );
646648 if (ndp16_datagram [ndx ].wDatagramIndex > len ) {
647- ERROR_OUT (" ill start of datagram[%d]: %d (%d)\n" , ndx , ndp16_datagram [ndx ].wDatagramIndex , len );
649+ ERROR_OUT ("(EE) ill start of datagram[%d]: %d (%d)\n" , ndx , ndp16_datagram [ndx ].wDatagramIndex , len );
648650 return false;
649651 }
650652 if (ndp16_datagram [ndx ].wDatagramIndex + ndp16_datagram [ndx ].wDatagramLength > len ) {
651- ERROR_OUT (" ill end of datagram[%d]: %d (%d)\n" , ndx , ndp16_datagram [ndx ].wDatagramIndex + ndp16_datagram [ndx ].wDatagramLength , len );
653+ ERROR_OUT ("(EE) ill end of datagram[%d]: %d (%d)\n" , ndx , ndp16_datagram [ndx ].wDatagramIndex + ndp16_datagram [ndx ].wDatagramLength , len );
652654 return false;
653655 }
654656 ++ ndx ;
@@ -685,10 +687,10 @@ static void recv_transfer_datagram_to_glue_logic(void)
685687 + sizeof (ndp16_t ));
686688
687689 if (ndp16_datagram [ncm_interface .recv_glue_ntb_datagram_ndx ].wDatagramIndex == 0 ) {
688- ERROR_OUT (" SOMETHING WENT WRONG 1\n" );
690+ ERROR_OUT ("(EE) SOMETHING WENT WRONG 1\n" );
689691 }
690692 else if (ndp16_datagram [ncm_interface .recv_glue_ntb_datagram_ndx ].wDatagramLength == 0 ) {
691- ERROR_OUT (" SOMETHING WENT WRONG 2\n" );
693+ ERROR_OUT ("(EE) SOMETHING WENT WRONG 2\n" );
692694 }
693695 else {
694696 uint16_t datagramIndex = ndp16_datagram [ncm_interface .recv_glue_ntb_datagram_ndx ].wDatagramIndex ;
@@ -740,7 +742,7 @@ bool tud_network_can_xmit(uint16_t size)
740742 return true;
741743 }
742744 xmit_start_if_possible (ncm_interface .rhport );
743- ERROR_OUT (" tud_network_can_xmit: request blocked\n" ); // could happen if all xmit buffers are full (but should happen rarely)
745+ ERROR_OUT ("(II) tud_network_can_xmit: request blocked\n" ); // could happen if all xmit buffers are full (but should happen rarely)
744746 return false;
745747} // tud_network_can_xmit
746748
@@ -755,7 +757,7 @@ void tud_network_xmit(void *ref, uint16_t arg)
755757 DEBUG_OUT ("tud_network_xmit(%p, %d)\n" , ref , arg );
756758
757759 if (ncm_interface .xmit_glue_ntb == NULL ) {
758- ERROR_OUT ("tud_network_xmit: no buffer\n" ); // must not happen (really)
760+ ERROR_OUT ("(EE) tud_network_xmit: no buffer\n" ); // must not happen (really)
759761 return ;
760762 }
761763
@@ -772,7 +774,7 @@ void tud_network_xmit(void *ref, uint16_t arg)
772774 ntb -> nth .wBlockLength += size + XMIT_ALIGN_OFFSET (size );
773775
774776 if (ntb -> nth .wBlockLength > CFG_TUD_NCM_OUT_NTB_MAX_SIZE ) {
775- ERROR_OUT ("tud_network_xmit: buffer overflow\n" ); // must not happen (really)
777+ ERROR_OUT ("(II) tud_network_xmit: buffer overflow\n" ); // must not happen (really)
776778 return ;
777779 }
778780
@@ -924,7 +926,7 @@ bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
924926 DEBUG_OUT (" EP_OUT %d %d %d %u\n" , rhport , ep_addr , result , (unsigned )xferred_bytes );
925927 if ( !recv_validate_datagram ( ncm_interface .recv_tinyusb_ntb , xferred_bytes )) {
926928 // verification failed: ignore NTB and return it to free
927- ERROR_OUT (" VALIDATION FAILED. WHAT CAN WE DO IN THIS CASE?\n" );
929+ ERROR_OUT ("(EE) VALIDATION FAILED. WHAT CAN WE DO IN THIS CASE?\n" );
928930 }
929931 else {
930932 // packet ok -> put it into ready list
0 commit comments