Skip to content

Commit

Permalink
Merge pull request hathach#2947 from espressif/fix/ncm_buffer_checks
Browse files Browse the repository at this point in the history
fix(ncm): Use IN buffer for transmit checks
  • Loading branch information
HiFiPhile authored Jan 15, 2025
2 parents 76fe039 + 679065c commit 880aae4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/class/net/ncm_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ static bool xmit_requested_datagram_fits_into_current_ntb(uint16_t datagram_size
if (ncm_interface.xmit_glue_ntb_datagram_ndx >= CFG_TUD_NCM_IN_MAX_DATAGRAMS_PER_NTB) {
return false;
}
if (ncm_interface.xmit_glue_ntb->nth.wBlockLength + datagram_size + XMIT_ALIGN_OFFSET(datagram_size) > CFG_TUD_NCM_OUT_NTB_MAX_SIZE) {
if (ncm_interface.xmit_glue_ntb->nth.wBlockLength + datagram_size + XMIT_ALIGN_OFFSET(datagram_size) > CFG_TUD_NCM_IN_NTB_MAX_SIZE) {
return false;
}
return true;
Expand Down Expand Up @@ -674,7 +674,7 @@ static void recv_transfer_datagram_to_glue_logic(void) {
bool tud_network_can_xmit(uint16_t size) {
TU_LOG_DRV("tud_network_can_xmit(%d)\n", size);

TU_ASSERT(size <= CFG_TUD_NCM_OUT_NTB_MAX_SIZE - (sizeof(nth16_t) + sizeof(ndp16_t) + 2 * sizeof(ndp16_datagram_t)), false);
TU_ASSERT(size <= CFG_TUD_NCM_IN_NTB_MAX_SIZE - (sizeof(nth16_t) + sizeof(ndp16_t) + 2 * sizeof(ndp16_datagram_t)), false);

if (xmit_requested_datagram_fits_into_current_ntb(size) || xmit_setup_next_glue_ntb()) {
// -> everything is fine
Expand Down Expand Up @@ -709,7 +709,7 @@ void tud_network_xmit(void *ref, uint16_t arg) {

ntb->nth.wBlockLength += (uint16_t) (size + XMIT_ALIGN_OFFSET(size));

if (ntb->nth.wBlockLength > CFG_TUD_NCM_OUT_NTB_MAX_SIZE) {
if (ntb->nth.wBlockLength > CFG_TUD_NCM_IN_NTB_MAX_SIZE) {
TU_LOG_DRV("(EE) tud_network_xmit: buffer overflow\n"); // must not happen (really)
return;
}
Expand Down

0 comments on commit 880aae4

Please sign in to comment.