Receiving Packets and Management Frames

NetDev_Rx() is called by μC/TCP-IP’s Receive task after the Interrupt Service Routine handler has signaled to the Receive task that a receive event has occurred. NetDev_Rx() requires that the device driver return a pointer to the data area containing the received data and return the size of the received frame via pointer.

Receive Buffer Structure

Since NetDev_Rx() can be called to receive management frames and data packets, all wireless receive buffers must contain an offset before the data area to specify the frame type. So to understand data reception, you first need to understand the structure of receive buffers.

Figure - Wireless receive buffer structure

(1)  The buffer offset is specified within the device’s Memory configuration. The offset must be at least equal to one octet to handle the Frame type. The offset can include option control data for demultiplex and or to respect the buffer alignment.

(2) The frame type space is always the first octet of the buffer. If receiving data packet, set the frame type equal to NET_IF_WIFI_DATA_PKT and the packet will be processed by the stack. For a management frame the byte must be set equal to NET_IF_WIFI_MGMT_FRAME, in this case NetDev_MgmtDemux() will be called after return to analyses the management frame and signal the Wireless Manager or update the driver data’s state.

(3) The receive buffer can include extra space to help to demultiplex a management frame or to respect buffer alignment required by the device’s BSP function.

(4) The pointer passed to the network device’s BSP function pointer, NetDev_WiFi_SPI_WrRd(), must point to the frame data area.


Receiving Frames

NetDev_Rx() should perform the following actions:

  1. Read the interrupt register which should be done by writing and reading on the SPI bus. This is performed by following the procedure to access the SPI bus. Also, the frame to receive must be know (Management frame or data packet). You should use small local buffer to write and read to complete that step.
  2. Check for errors, if applicable. If an error occurs during reception, the driver should set *size to 0 and *p_data to (CPU_INT08U *)0 and return. Additional steps may be necessary depending on the device being serviced.
  3. Get the size of the received frame and get a new data buffer area by calling NetBuf_GetDataPtr(). If memory is not available, an error will be returned and the device driver should set *size to 0 and *p_data to (CPU_INT08U *)0.
  4. If an error does not occur while getting a new data area, *p_data must be set to the address of the data area.
  5. Set the frame type within the receive buffer equal to NET_IF_WIFI_DATA_PKT for a packet which must be processed by the stack and equal to NET_IF_WIFI_MGMT_FRAME for any management frame which will be passed to NetDev_MgmtDemux() to demultiplex the management frame.
  6. Read from the device to the receive buffer data area by calling the network device’s BSP function pointer, NetDev_WiFi_SPI_WrRd(), with an appropriate pointer to the data area of the receive buffer.
  7. Set p_err to NET_DEV_ERR_NONE and return from the receive function. Otherwise, set p_err to an appropriate network device error code.

Transmit Completed Notification

Since the SPI cannot be accessed within the ISR handler most of time all interrupts type are read in NetDev_Rx(). Also, when the ISR type is for a transmit completed notification, it is not recommended to notify the stack by the function and return an error since the reception statistics and errors counter will be affected. Instead it is recommended to return a management frame that contains the address of the data area successfully transmitted. Since all management frame are processed by NetDev_MgmtDemux(), the step to notify the stack should be done into it.