FreeBSD/sys/netgraph/bluetooth/socket/ng_btsocket_sco.c
/*
 * Process LP_ConnectCfm event from the lower layer protocol
 */
Process LP_ConnectCfm event from the lower layer protocol
Process LP_ConnectCfm event from the lower layer protocol
static int
ng_btsocket_sco_process_lp_con_cfm(struct ng_mesg *msg,
		ng_btsocket_sco_rtentry_p rt)
{
	ng_hci_lp_con_cfm_ep	*ep = NULL;
	ng_btsocket_sco_pcb_t	*pcb = NULL;
	int			 error = 0;
	if (msg->header.arglen != sizeof(*ep))
		return (EMSGSIZE);
	ep = (ng_hci_lp_con_cfm_ep *)(msg->data);
	mtx_lock(&ng_btsocket_sco_sockets_mtx);
	pcb = ng_btsocket_sco_pcb_by_addrs(&rt->src, &ep->bdaddr);
	if (pcb == NULL) {
		mtx_unlock(&ng_btsocket_sco_sockets_mtx);
		return (ENOENT);
	}
	NG_BTSOCKET_SCO_INFO(
"%s: Got LP_ConnectCfm response, src bdaddr=%x:%x:%x:%x:%x:%x, " \
"dst bdaddr=%x:%x:%x:%x:%x:%x, status=%d, handle=%d, state=%d\n",
		__func__,
		pcb->src.b[5], pcb->src.b[4], pcb->src.b[3],
		pcb->src.b[2], pcb->src.b[1], pcb->src.b[0],
		pcb->dst.b[5], pcb->dst.b[4], pcb->dst.b[3],
		pcb->dst.b[2], pcb->dst.b[1], pcb->dst.b[0],
		ep->status, ep->con_handle, pcb->state);
	if (pcb->state != NG_BTSOCKET_SCO_CONNECTING) {
		mtx_unlock(&pcb->pcb_mtx);
		mtx_unlock(&ng_btsocket_sco_sockets_mtx);
		return (ENOENT);
	}
	ng_btsocket_sco_untimeout(pcb);
	if (ep->status == 0) {
		pcb->con_handle = ep->con_handle; 
		pcb->state = NG_BTSOCKET_SCO_OPEN;
		soisconnected(pcb->so); 
	} else {
		pcb->so->so_error = ECONNREFUSED; 
		pcb->state = NG_BTSOCKET_SCO_CLOSED;
		soisdisconnected(pcb->so); 
	}
	mtx_unlock(&pcb->pcb_mtx);
	mtx_unlock(&ng_btsocket_sco_sockets_mtx);
	return (error);
}
static int ng_btsocket_sco_process_lp_con_cfm ( struct ng_mesg * msg , ng_btsocket_sco_rtentry_p rt ) { ng_hci_lp_con_cfm_ep * ep = NULL ; ng_btsocket_sco_pcb_t * pcb = NULL ; int error = 0 ; if ( msg -> header . arglen != sizeof ( * ep ) ) return ( EMSGSIZE ) ; ep = ( ng_hci_lp_con_cfm_ep * ) ( msg -> data ) ; mtx_lock ( & ng_btsocket_sco_sockets_mtx ) ; pcb = ng_btsocket_sco_pcb_by_addrs ( & rt -> src , & ep -> bdaddr ) ; if ( pcb == NULL ) { mtx_unlock ( & ng_btsocket_sco_sockets_mtx ) ; return ( ENOENT ) ; } NG_BTSOCKET_SCO_INFO ( " " " \n " , __func__ , pcb -> src . b [ 5 ] , pcb -> src . b [ 4 ] , pcb -> src . b [ 3 ] , pcb -> src . b [ 2 ] , pcb -> src . b [ 1 ] , pcb -> src . b [ 0 ] , pcb -> dst . b [ 5 ] , pcb -> dst . b [ 4 ] , pcb -> dst . b [ 3 ] , pcb -> dst . b [ 2 ] , pcb -> dst . b [ 1 ] , pcb -> dst . b [ 0 ] , ep -> status , ep -> con_handle , pcb -> state ) ; if ( pcb -> state != NG_BTSOCKET_SCO_CONNECTING ) { mtx_unlock ( & pcb -> pcb_mtx ) ; mtx_unlock ( & ng_btsocket_sco_sockets_mtx ) ; return ( ENOENT ) ; } ng_btsocket_sco_untimeout ( pcb ) ; if ( ep -> status == 0 ) { pcb -> con_handle = ep -> con_handle ; pcb -> state = NG_BTSOCKET_SCO_OPEN ; soisconnected ( pcb -> so ) ; } else { pcb -> so -> so_error = ECONNREFUSED ; pcb -> state = NG_BTSOCKET_SCO_CLOSED ; soisdisconnected ( pcb -> so ) ; } mtx_unlock ( & pcb -> pcb_mtx ) ; mtx_unlock ( & ng_btsocket_sco_sockets_mtx ) ; return ( error ) ; }
Process LP_ConnectCfm event from the lower layer protocol
Process LP_ConnectCfm event from the lower layer protocol
/* Look for the socket with the token */ /* pcb is locked */ /*
		 * Connection is open. Update connection handle and
		 * socket state
		 */ /*
		 * We have failed to open connection, so disconnect the socket
		 */ /* XXX convert status ??? */