FreeBSD/usr.sbin/bluetooth/btpand/bnep.c
/*
 * receive BNEP packet
 * return true if packet is to be forwarded
 */
receive BNEP packet
return true if packet is to be forwarded
receive BNEP packet return true if packet is to be forwarded
bool
bnep_recv(packet_t *pkt)
{
	size_t len;
	uint8_t type;
	if (pkt->len < 1)
		return false;
	type = pkt->ptr[0];
	packet_adj(pkt, 1);
	switch (BNEP_TYPE(type)) {
	case BNEP_GENERAL_ETHERNET:
		if (pkt->len < (ETHER_ADDR_LEN * 2) + ETHER_TYPE_LEN) {
			log_debug("dropped short packet (type 0x%2.2x)", type);
			return false;
		}
		pkt->dst = pkt->ptr;
		packet_adj(pkt, ETHER_ADDR_LEN);
		pkt->src = pkt->ptr;
		packet_adj(pkt, ETHER_ADDR_LEN);
		pkt->type = pkt->ptr;
		packet_adj(pkt, ETHER_TYPE_LEN);
		break;
	case BNEP_CONTROL:
		len = bnep_recv_control(pkt->chan, pkt->ptr, pkt->len, false);
		if (len == 0)
			return false;
		packet_adj(pkt, len);
		break;
	case BNEP_COMPRESSED_ETHERNET:
		if (pkt->len < ETHER_TYPE_LEN) {
			log_debug("dropped short packet (type 0x%2.2x)", type);
			return false;
		}
		pkt->dst = pkt->chan->laddr;
		pkt->src = pkt->chan->raddr;
		pkt->type = pkt->ptr;
		packet_adj(pkt, ETHER_TYPE_LEN);
		break;
	case BNEP_COMPRESSED_ETHERNET_SRC_ONLY:
		if (pkt->len < ETHER_ADDR_LEN + ETHER_TYPE_LEN) {
			log_debug("dropped short packet (type 0x%2.2x)", type);
			return false;
		}
		pkt->dst = pkt->chan->laddr;
		pkt->src = pkt->ptr;
		packet_adj(pkt, ETHER_ADDR_LEN);
		pkt->type = pkt->ptr;
		packet_adj(pkt, ETHER_TYPE_LEN);
		break;
	case BNEP_COMPRESSED_ETHERNET_DST_ONLY:
		if (pkt->len < ETHER_ADDR_LEN + ETHER_TYPE_LEN) {
			log_debug("dropped short packet (type 0x%2.2x)", type);
			return false;
		}
		pkt->dst = pkt->ptr;
		packet_adj(pkt, ETHER_ADDR_LEN);
		pkt->src = pkt->chan->raddr;
		pkt->type = pkt->ptr;
		packet_adj(pkt, ETHER_TYPE_LEN);
		break;
	default:
		log_debug("dropped packet with reserved type 0x%2.2x", type);
		return false;
	}
	if (BNEP_TYPE_EXT(type)
	    && !bnep_recv_extension(pkt))
		return false;	
	if (BNEP_TYPE(type) == BNEP_CONTROL
	    || pkt->chan->state != CHANNEL_OPEN)
		return false;	
	return true;
}
bool bnep_recv ( packet_t * pkt ) { size_t len ; uint8_t type ; if ( pkt -> len < 1 ) return false ; type = pkt -> ptr [ 0 ] ; packet_adj ( pkt , 1 ) ; switch ( BNEP_TYPE ( type ) ) { case BNEP_GENERAL_ETHERNET : if ( pkt -> len < ( ETHER_ADDR_LEN * 2 ) + ETHER_TYPE_LEN ) { log_debug ( " " , type ) ; return false ; } pkt -> dst = pkt -> ptr ; packet_adj ( pkt , ETHER_ADDR_LEN ) ; pkt -> src = pkt -> ptr ; packet_adj ( pkt , ETHER_ADDR_LEN ) ; pkt -> type = pkt -> ptr ; packet_adj ( pkt , ETHER_TYPE_LEN ) ; break ; case BNEP_CONTROL : len = bnep_recv_control ( pkt -> chan , pkt -> ptr , pkt -> len , false ) ; if ( len == 0 ) return false ; packet_adj ( pkt , len ) ; break ; case BNEP_COMPRESSED_ETHERNET : if ( pkt -> len < ETHER_TYPE_LEN ) { log_debug ( " " , type ) ; return false ; } pkt -> dst = pkt -> chan -> laddr ; pkt -> src = pkt -> chan -> raddr ; pkt -> type = pkt -> ptr ; packet_adj ( pkt , ETHER_TYPE_LEN ) ; break ; case BNEP_COMPRESSED_ETHERNET_SRC_ONLY : if ( pkt -> len < ETHER_ADDR_LEN + ETHER_TYPE_LEN ) { log_debug ( " " , type ) ; return false ; } pkt -> dst = pkt -> chan -> laddr ; pkt -> src = pkt -> ptr ; packet_adj ( pkt , ETHER_ADDR_LEN ) ; pkt -> type = pkt -> ptr ; packet_adj ( pkt , ETHER_TYPE_LEN ) ; break ; case BNEP_COMPRESSED_ETHERNET_DST_ONLY : if ( pkt -> len < ETHER_ADDR_LEN + ETHER_TYPE_LEN ) { log_debug ( " " , type ) ; return false ; } pkt -> dst = pkt -> ptr ; packet_adj ( pkt , ETHER_ADDR_LEN ) ; pkt -> src = pkt -> chan -> raddr ; pkt -> type = pkt -> ptr ; packet_adj ( pkt , ETHER_TYPE_LEN ) ; break ; default : log_debug ( " " , type ) ; return false ; } if ( BNEP_TYPE_EXT ( type ) && ! bnep_recv_extension ( pkt ) ) return false ; if ( BNEP_TYPE ( type ) == BNEP_CONTROL || pkt -> chan -> state != CHANNEL_OPEN ) return false ; return true ; }
receive BNEP packet
 return true if packet is to be forwarded
receive BNEP packet return true if packet is to be forwarded
/*
		 * Any packet containing a reserved BNEP
		 * header packet type SHALL be dropped.
		 */ /* invalid extensions */ /* no forwarding */