@@ -864,13 +864,13 @@ static int cdc_ncm_send(const struct device *dev, struct net_pkt *const pkt)
864864{
865865 struct cdc_ncm_eth_data * const data = dev -> data ;
866866 struct usbd_class_data * c_data = data -> c_data ;
867- size_t len = net_pkt_get_len (pkt );
867+ size_t pkt_len = net_pkt_get_len (pkt );
868868 struct net_buf * buf ;
869869 union xmit_ntb_t * ntb ;
870870
871- LOG_DBG ("len: %d" , len );
871+ LOG_DBG ("len: %d" , pkt_len );
872872
873- if (len > sizeof (ntb -> data ))
873+ if (pkt_len > sizeof (ntb -> data )) // TODO minus header etc!
874874 {
875875 LOG_WRN ("Trying to send too large packet, drop" );
876876 return - ENOMEM ;
@@ -905,19 +905,23 @@ static int cdc_ncm_send(const struct device *dev, struct net_pkt *const pkt)
905905 ntb -> ndp .wNextNdpIndex = 0 ;
906906
907907 ntb -> ndp_datagram [0 ].wDatagramIndex = sys_cpu_to_le16 (sys_le16_to_cpu (ntb -> nth .wHeaderLength ) + sys_le16_to_cpu (ntb -> ndp .wLength ));
908- ntb -> ndp_datagram [0 ].wDatagramLength = sys_cpu_to_le16 (len );
908+ ntb -> ndp_datagram [0 ].wDatagramLength = sys_cpu_to_le16 (pkt_len );
909909 ntb -> ndp_datagram [1 ].wDatagramIndex = 0 ;
910910 ntb -> ndp_datagram [1 ].wDatagramLength = 0 ;
911911
912- ntb -> nth .wBlockLength = sys_cpu_to_le16 (sys_le16_to_cpu (ntb -> ndp_datagram [0 ].wDatagramIndex ) + sys_le16_to_cpu ( ntb -> ndp_datagram [ 0 ]. wDatagramLength ) );
912+ ntb -> nth .wBlockLength = sys_cpu_to_le16 (sys_le16_to_cpu (ntb -> ndp_datagram [0 ].wDatagramIndex ) + pkt_len );
913913
914- if (net_pkt_read (pkt , ntb -> data + sys_le16_to_cpu (ntb -> ndp_datagram [0 ].wDatagramIndex ), len ))
914+ // LOG_WRN("%p %d %d %d", ntb, ntb->ndp_datagram[0].wDatagramIndex, pkt_len, sys_le16_to_cpu(ntb->nth.wBlockLength));
915+
916+ if (net_pkt_read (pkt , ntb -> data + sys_le16_to_cpu (ntb -> ndp_datagram [0 ].wDatagramIndex ), pkt_len ))
915917 {
916918 LOG_ERR ("Failed copy net_pkt" );
917919 net_buf_unref (buf );
918920 return - ENOBUFS ;
919921 }
922+ // post: now the complete NTB is written.
920923
924+ // adjust length of net_buf accordingly
921925 net_buf_add (buf , sys_le16_to_cpu (ntb -> nth .wBlockLength ));
922926
923927 if (sys_le16_to_cpu (ntb -> nth .wBlockLength ) % cdc_ncm_get_bulk_in_mps (c_data ) == 0 )
0 commit comments