int ng_l2cap_lp_con_cfm(ng_l2cap_p l2cap, struct ng_mesg *msg) { ng_hci_lp_con_cfm_ep *ep = NULL; ng_l2cap_con_p con = NULL; int error = 0; /* Check message */ if (msg->header.arglen != sizeof(*ep)) { NG_L2CAP_ALERT( "%s: %s - invalid LP_ConnectCfm[Neg] message size\n", __func__, NG_NODE_NAME(l2cap->node)); error = EMSGSIZE; goto out; } ep = (ng_hci_lp_con_cfm_ep *) (msg->data); /* Check if we have requested/accepted this connection */ con = ng_l2cap_con_by_addr(l2cap, &ep->bdaddr); if (con == NULL) { NG_L2CAP_ERR( "%s: %s - unexpected LP_ConnectCfm event. Connection does not exist\n", __func__, NG_NODE_NAME(l2cap->node)); error = ENOENT; goto out; } /* Check connection state */ if (con->state != NG_L2CAP_W4_LP_CON_CFM) { NG_L2CAP_ALERT( "%s: %s - unexpected LP_ConnectCfm event. " \ "Invalid connection state, state=%d, con_handle=%d\n", __func__, NG_NODE_NAME(l2cap->node), con->state, con->con_handle); error = EINVAL; goto out; } /* * Looks like it is our confirmation. It is safe now to cancel * connection timer and notify upper layer. If timeout already * happened then ignore connection confirmation and let timeout * handle that. */ if ((error = ng_l2cap_lp_untimeout(con)) != 0) goto out; if (ep->status == 0) { con->state = NG_L2CAP_CON_OPEN; con->con_handle = ep->con_handle; ng_l2cap_lp_deliver(con); } else /* Negative confirmation - remove connection descriptor */ ng_l2cap_con_fail(con, ep->status); out: return (error); } /* ng_l2cap_lp_con_cfm */
int ng_l2cap_lp_discon_ind(ng_l2cap_p l2cap, struct ng_mesg *msg) { ng_hci_lp_discon_ind_ep *ep = NULL; ng_l2cap_con_p con = NULL; int error = 0; /* Check message */ if (msg->header.arglen != sizeof(*ep)) { NG_L2CAP_ALERT( "%s: %s - invalid LP_DisconnectInd message size\n", __func__, NG_NODE_NAME(l2cap->node)); error = EMSGSIZE; goto out; } ep = (ng_hci_lp_discon_ind_ep *) (msg->data); /* Check if we have this connection */ con = ng_l2cap_con_by_handle(l2cap, ep->con_handle); if (con == NULL) { NG_L2CAP_ERR( "%s: %s - unexpected LP_DisconnectInd event. " \ "Connection does not exist, con_handle=%d\n", __func__, NG_NODE_NAME(l2cap->node), ep->con_handle); error = ENOENT; goto out; } /* XXX Verify connection state -- do we need to check this? */ if (con->state != NG_L2CAP_CON_OPEN) { NG_L2CAP_ERR( "%s: %s - unexpected LP_DisconnectInd event. " \ "Invalid connection state, state=%d, con_handle=%d\n", __func__, NG_NODE_NAME(l2cap->node), con->state, con->con_handle); error = EINVAL; goto out; } /* * Notify upper layer and remove connection * Note: The connection could have auto disconnect timeout set. Try * to remove it. If auto disconnect timeout happened then ignore * disconnect indication and let timeout handle that. */ if (con->flags & NG_L2CAP_CON_AUTO_DISCON_TIMO) if ((error = ng_l2cap_discon_untimeout(con)) != 0) return (error); ng_l2cap_con_fail(con, ep->reason); out: return (error); } /* ng_l2cap_lp_discon_ind */
int ng_l2cap_lp_discon_ind(ng_l2cap_p l2cap, struct ng_mesg *msg) { ng_hci_lp_discon_ind_ep *ep = NULL; ng_l2cap_con_p con = NULL; int error = 0; /* Check message */ if (msg->header.arglen != sizeof(*ep)) { NG_L2CAP_ALERT( "%s: %s - invalid LP_DisconnectInd message size\n", __func__, NG_NODE_NAME(l2cap->node)); error = EMSGSIZE; goto out; } ep = (ng_hci_lp_discon_ind_ep *) (msg->data); /* Check if we have this connection */ con = ng_l2cap_con_by_handle(l2cap, ep->con_handle); if (con == NULL) { NG_L2CAP_ERR( "%s: %s - unexpected LP_DisconnectInd event. " \ "Connection does not exist, con_handle=%d\n", __func__, NG_NODE_NAME(l2cap->node), ep->con_handle); error = ENOENT; goto out; } /* XXX Verify connection state -- do we need to check this? */ if (con->state != NG_L2CAP_CON_OPEN) { NG_L2CAP_ERR( "%s: %s - unexpected LP_DisconnectInd event. " \ "Invalid connection state, state=%d, con_handle=%d\n", __func__, NG_NODE_NAME(l2cap->node), con->state, con->con_handle); error = EINVAL; goto out; } /* Notify upper layer and remove connection */ con->state = NG_L2CAP_CON_CLOSED; ng_l2cap_con_fail(con, ep->reason); out: return (error); } /* ng_l2cap_lp_discon_ind */