FreeBSD/sys/dev/usb/wlan/if_upgt.c
/*
 * When a rx data came in the function returns a mbuf and a rssi values.
 */
When a rx data came in the function returns a mbuf and a rssi values.
When a rx data came in the function returns a mbuf and a rssi values .
static struct mbuf *
upgt_rxeof(struct usb_xfer *xfer, struct upgt_data *data, int *rssi)
{
	struct mbuf *m = NULL;
	struct upgt_softc *sc = usbd_xfer_softc(xfer);
	struct upgt_lmac_header *header;
	struct upgt_lmac_eeprom *eeprom;
	uint8_t h1_type;
	uint16_t h2_type;
	int actlen, sumlen;
	usbd_xfer_status(xfer, &actlen, &sumlen, NULL, NULL);
	UPGT_ASSERT_LOCKED(sc);
	if (actlen < 1)
		return (NULL);
	if (!(sc->sc_flags & UPGT_FLAG_FWLOADED) &&
	    (memcmp(data->buf, "OK", 2) == 0)) {
		sc->sc_flags |= UPGT_FLAG_FWLOADED;
		wakeup_one(sc);
		return (NULL);
	}
	if (actlen < (int)UPGT_RX_MINSZ)
		return (NULL);
	header = (struct upgt_lmac_header *)(data->buf + 4);
	h1_type = header->header1.type;
	h2_type = le16toh(header->header2.type);
	if (h1_type == UPGT_H1_TYPE_CTRL && h2_type == UPGT_H2_TYPE_EEPROM) {
		eeprom = (struct upgt_lmac_eeprom *)(data->buf + 4);
		uint16_t eeprom_offset = le16toh(eeprom->offset);
		uint16_t eeprom_len = le16toh(eeprom->len);
		DPRINTF(sc, UPGT_DEBUG_FW,
		    "received EEPROM block (offset=%d, len=%d)\n",
		    eeprom_offset, eeprom_len);
		memcpy(sc->sc_eeprom + eeprom_offset,
		    data->buf + sizeof(struct upgt_lmac_eeprom) + 4,
		    eeprom_len);
		wakeup(sc);
	} else if (h1_type == UPGT_H1_TYPE_CTRL &&
	    h2_type == UPGT_H2_TYPE_TX_DONE) {
		DPRINTF(sc, UPGT_DEBUG_XMIT, "%s: received 802.11 TX done\n",
		    __func__);
		upgt_tx_done(sc, data->buf + 4);
	} else if (h1_type == UPGT_H1_TYPE_RX_DATA ||
	    h1_type == UPGT_H1_TYPE_RX_DATA_MGMT) {
		DPRINTF(sc, UPGT_DEBUG_RECV, "%s: received 802.11 RX data\n",
		    __func__);
		m = upgt_rx(sc, data->buf + 4, le16toh(header->header1.len),
		    rssi);
	} else if (h1_type == UPGT_H1_TYPE_CTRL &&
	    h2_type == UPGT_H2_TYPE_STATS) {
		DPRINTF(sc, UPGT_DEBUG_STAT, "%s: received statistic data\n",
		    __func__);
	} else {
		DPRINTF(sc, UPGT_DEBUG_INTR,
		    "received unknown frame type 0x%02x\n",
		    header->header1.type);
	}
	return (m);
}
static struct mbuf * upgt_rxeof ( struct usb_xfer * xfer , struct upgt_data * data , int * rssi ) { struct mbuf * m = NULL ; struct upgt_softc * sc = usbd_xfer_softc ( xfer ) ; struct upgt_lmac_header * header ; struct upgt_lmac_eeprom * eeprom ; uint8_t h1_type ; uint16_t h2_type ; int actlen , sumlen ; usbd_xfer_status ( xfer , & actlen , & sumlen , NULL , NULL ) ; UPGT_ASSERT_LOCKED ( sc ) ; if ( actlen < 1 ) return ( NULL ) ; if ( ! ( sc -> sc_flags & UPGT_FLAG_FWLOADED ) && ( memcmp ( data -> buf , " " , 2 ) == 0 ) ) { sc -> sc_flags |= UPGT_FLAG_FWLOADED ; wakeup_one ( sc ) ; return ( NULL ) ; } if ( actlen < ( int ) UPGT_RX_MINSZ ) return ( NULL ) ; header = ( struct upgt_lmac_header * ) ( data -> buf + 4 ) ; h1_type = header -> header1 . type ; h2_type = le16toh ( header -> header2 . type ) ; if ( h1_type == UPGT_H1_TYPE_CTRL && h2_type == UPGT_H2_TYPE_EEPROM ) { eeprom = ( struct upgt_lmac_eeprom * ) ( data -> buf + 4 ) ; uint16_t eeprom_offset = le16toh ( eeprom -> offset ) ; uint16_t eeprom_len = le16toh ( eeprom -> len ) ; DPRINTF ( sc , UPGT_DEBUG_FW , " \n " , eeprom_offset , eeprom_len ) ; memcpy ( sc -> sc_eeprom + eeprom_offset , data -> buf + sizeof ( struct upgt_lmac_eeprom ) + 4 , eeprom_len ) ; wakeup ( sc ) ; } else if ( h1_type == UPGT_H1_TYPE_CTRL && h2_type == UPGT_H2_TYPE_TX_DONE ) { DPRINTF ( sc , UPGT_DEBUG_XMIT , " \n " , __func__ ) ; upgt_tx_done ( sc , data -> buf + 4 ) ; } else if ( h1_type == UPGT_H1_TYPE_RX_DATA || h1_type == UPGT_H1_TYPE_RX_DATA_MGMT ) { DPRINTF ( sc , UPGT_DEBUG_RECV , " \n " , __func__ ) ; m = upgt_rx ( sc , data -> buf + 4 , le16toh ( header -> header1 . len ) , rssi ) ; } else if ( h1_type == UPGT_H1_TYPE_CTRL && h2_type == UPGT_H2_TYPE_STATS ) { DPRINTF ( sc , UPGT_DEBUG_STAT , " \n " , __func__ ) ; } else { DPRINTF ( sc , UPGT_DEBUG_INTR , " \n " , header -> header1 . type ) ; } return ( m ) ; }
When a rx data came in the function returns a mbuf and a rssi values.
When a rx data came in the function returns a mbuf and a rssi values .
/* Check only at the very beginning.  */ /*
	 * Check what type of frame came in.
	 */ /* EEPROM data has arrived in time, wakeup.  */ /* TODO: what could we do with the statistic data? */ /* ignore unknown frame types */