sys/netgraph7/bluetooth/hci/ng_hci_cmds.c
/*
 * Send HCI command to the driver.
 */
Send HCI command to the driver.
Send HCI command to the driver .
int
ng_hci_send_command(ng_hci_unit_p unit)
{
	struct mbuf	*m0 = NULL, *m = NULL;
	int		 free, error = 0;
	if (unit->state & NG_HCI_UNIT_COMMAND_PENDING)
		return (0);
	NG_HCI_BUFF_CMD_GET(unit->buffer, free);
	if (free == 0)
		return (0);
	if (unit->drv == NULL || NG_HOOK_NOT_VALID(unit->drv)) {
		NG_HCI_WARN(
"%s: %s - hook \"%s\" is not connected or valid\n",
			__func__, NG_NODE_NAME(unit->node), NG_HCI_HOOK_DRV);
		NG_BT_MBUFQ_DRAIN(&unit->cmdq);
		return (ENOTCONN);
	}
	m0 = NG_BT_MBUFQ_FIRST(&unit->cmdq);
	if (m0 == NULL)
		return (0);
	ng_hci_mtap(unit, m0);
	m = m_dup(m0, M_NOWAIT);
	if (m != NULL)
		NG_SEND_DATA_ONLY(error, unit->drv, m);
	else
		error = ENOBUFS;
	if (error != 0)
		NG_HCI_ERR(
"%s: %s - could not send HCI command, error=%d\n",
			__func__, NG_NODE_NAME(unit->node), error);
	NG_HCI_BUFF_CMD_USE(unit->buffer, 1);
	NG_HCI_STAT_CMD_SENT(unit->stat);
	NG_HCI_STAT_BYTES_SENT(unit->stat, m0->m_pkthdr.len);
	ng_hci_command_timeout(unit);
	return (0);
}
int ng_hci_send_command ( ng_hci_unit_p unit ) { struct mbuf * m0 = NULL , * m = NULL ; int free , error = 0 ; if ( unit -> state & NG_HCI_UNIT_COMMAND_PENDING ) return ( 0 ) ; NG_HCI_BUFF_CMD_GET ( unit -> buffer , free ) ; if ( free == 0 ) return ( 0 ) ; if ( unit -> drv == NULL || NG_HOOK_NOT_VALID ( unit -> drv ) ) { NG_HCI_WARN ( " \" \" \n " , __func__ , NG_NODE_NAME ( unit -> node ) , NG_HCI_HOOK_DRV ) ; NG_BT_MBUFQ_DRAIN ( & unit -> cmdq ) ; return ( ENOTCONN ) ; } m0 = NG_BT_MBUFQ_FIRST ( & unit -> cmdq ) ; if ( m0 == NULL ) return ( 0 ) ; ng_hci_mtap ( unit , m0 ) ; m = m_dup ( m0 , M_NOWAIT ) ; if ( m != NULL ) NG_SEND_DATA_ONLY ( error , unit -> drv , m ) ; else error = ENOBUFS ; if ( error != 0 ) NG_HCI_ERR ( " \n " , __func__ , NG_NODE_NAME ( unit -> node ) , error ) ; NG_HCI_BUFF_CMD_USE ( unit -> buffer , 1 ) ; NG_HCI_STAT_CMD_SENT ( unit -> stat ) ; NG_HCI_STAT_BYTES_SENT ( unit -> stat , m0 -> m_pkthdr . len ) ; ng_hci_command_timeout ( unit ) ; return ( 0 ) ; }
Send HCI command to the driver.
Send HCI command to the driver .
/* Check if other command is pending */ /* Check if unit can accept our command */ /* Check if driver hook is still ok */ /* 
	 * Get first command from queue, give it to RAW hook then 
	 * make copy of it and send it to the driver
	 */ /*
	 * Even if we were not able to send command we still pretend
	 * that everything is OK and let timeout handle that.
	 */ /*
	 * Note: ng_hci_command_timeout() will set 
	 * NG_HCI_UNIT_COMMAND_PENDING flag
	 */