+TCP port buffers CYW43439

I have two interfaces, one the stm32h5, the other a cyw43439 wifi chip. I’m in the process of writing the networkinterface for the wifi. If possible, I’d like to zero copy, but I can’t seem to see a way around it.

The issue is that the core stm32 Airoc buffer allocation uses arbitrary offsets, unlike the fixed ipBUFFER_PADDING offsets in the NetworkBufferDescriptor_t Buffer 2 allocations. The reason for this I suppose is that the Airoc library can add or remove headers from/to the packet and forward to be consumed. Is there some workaround possible aside from modifications to the NetworkBufferDescriptor_t?

So to solve this, I would need the ability to shift the pucEthernetBuffer the add_remove_amount and then somehow to allow the core tcp to free this as normal. Or maybe zero copy is not workable at present?

Here is my present non zero copy code.

typedef struct {
  void * allocated;
  void * currentPtr;
  uint16_t allocatedLength;
  uint16_t length;
} pbuf_t;

whd_result_t cy_host_buffer_get(whd_buffer_t *buffer,
                                whd_buffer_dir_t direction, uint16_t size,
                                uint32_t timeout_ms) { //
  pbuf_t *pxReturn = NULL;
  pxReturn = x_malloc(sizeof(pbuf_t), XMEM_HEAP_DEFAULT);
  pxReturn->allocated = x_malloc(size, XMEM_HEAP_DEFAULT);
  pxReturn->currentPtr = pxReturn->allocated;
  pxReturn->allocatedLength = size;
  pxReturn->length = size;
  if (pxReturn != NULL) {
    *buffer = pxReturn;
    return WHD_SUCCESS;
  } else {
    return WHD_BUFFER_ALLOC_FAIL;
  }
}

void cy_buffer_release(whd_buffer_t buffer, whd_buffer_dir_t direction) {
  configASSERT(buffer != NULL);
  pbuf_t *p = buffer;
  x_free(p->allocated);
  x_free(p);
}

uint8_t *cy_buffer_get_current_piece_data_pointer(whd_buffer_t buffer) {
  configASSERT(buffer != NULL);
  pbuf_t *p = buffer;
  return (uint8_t *)p->currentPtr;
}

uint16_t cy_buffer_get_current_piece_size(whd_buffer_t buffer) {
  configASSERT(buffer != NULL);
  pbuf_t *p = buffer;
  return (uint16_t)p->length;
}

whd_result_t cy_buffer_set_size(whd_buffer_t buffer, unsigned short size) {
  configASSERT(buffer != NULL);
  pbuf_t *p = buffer;
  configASSERT(size + (p->currentPtr - p->allocated) < p->allocatedLength);
  p->length = size;
  return CY_RSLT_SUCCESS;
}

whd_result_t cy_buffer_add_remove_at_front(whd_buffer_t *buffer,
                                           int32_t add_remove_amount) {
  configASSERT(buffer != NULL);
  pbuf_t *p = *buffer;
  p->currentPtr += add_remove_amount;
  return WHD_SUCCESS;
}