1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
24 */
25
26/*
27 * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
28 * Use is subject to license terms.
29 */
30
31/*
32 *
33 * MODULE: dapl_ep_dup_connect.c
34 *
35 * PURPOSE: Endpoint management
36 * Description: Interfaces in this file are completely described in
37 *		the DAPL 1.1 API, Chapter 6, section 5
38 *
39 * $Id: dapl_ep_dup_connect.c,v 1.8 2003/06/16 17:53:32 sjs2 Exp $
40 */
41
42#include "dapl.h"
43#include "dapl_ep_util.h"
44#include "dapl_adapter_util.h"
45
46/*
47 * dapl_ep_dup_connect
48 *
49 * DAPL Requirements Version xxx, 6.5.8
50 *
51 * Requst that a connection be established between the local Endpoint
52 * and a remote Endpoint. The remote Endpoint is identified by the
53 * dup_ep.
54 *
55 * Input:
56 *	ep_handle
57 *	ep_dup_handle
58 *	conn_qual
59 *	timeout
60 *	private_data_size
61 *	private_data
62 *	qos
63 *
64 * Output:
65 *	none
66 *
67 * Returns:
68 *	DAT_SUCCESS
69 *	DAT_INSUFFICIENT_RESOURCES
70 *	DAT_INVALID_PARAMETER
71 *	DAT_INVALID_STATE
72 *	DAT_MODEL_NOT_SUPPORTED
73 */
74
75DAT_RETURN
76dapl_ep_dup_connect(
77	IN DAT_EP_HANDLE ep_handle,
78	IN DAT_EP_HANDLE ep_dup_handle,
79	IN DAT_TIMEOUT timeout,
80	IN DAT_COUNT private_data_size,
81	IN const DAT_PVOID private_data,
82	IN DAT_QOS qos)
83{
84	DAPL_EP *ep_dup_ptr;
85	DAT_RETURN dat_status;
86	DAT_IA_ADDRESS_PTR remote_ia_address_ptr;
87	DAT_CONN_QUAL remote_conn_qual;
88
89	ep_dup_ptr = (DAPL_EP *)ep_dup_handle;
90
91	/*
92	 * Verify the dup handle, which must be connected. All other
93	 * parameters will be verified by dapl_ep_connect
94	 */
95	if (DAPL_BAD_HANDLE(ep_dup_handle, DAPL_MAGIC_EP)) {
96		dat_status = DAT_ERROR(DAT_INVALID_HANDLE,
97		    DAT_INVALID_HANDLE_EP);
98		goto bail;
99	}
100	/*
101	 * Check both the EP state and the QP state: if we don't have a QP
102	 *  there is a problem.  Do this under a lock and pull out
103	 * the connection parameters for atomicity.
104	 */
105	dapl_os_lock(&ep_dup_ptr->header.lock);
106	if (ep_dup_ptr->param.ep_state != DAT_EP_STATE_CONNECTED) {
107		dapl_os_unlock(&ep_dup_ptr->header.lock);
108		dat_status = DAT_ERROR(DAT_INVALID_STATE,
109		    dapls_ep_state_subtype(ep_dup_ptr));
110		goto bail;
111	}
112	remote_ia_address_ptr = ep_dup_ptr->param.remote_ia_address_ptr;
113	remote_conn_qual = ep_dup_ptr->param.remote_port_qual;
114	dapl_os_unlock(&ep_dup_ptr->header.lock);
115
116	dat_status = dapl_ep_connect(ep_handle,
117	    remote_ia_address_ptr, remote_conn_qual, timeout,
118	    private_data_size, private_data, qos,
119	    DAT_CONNECT_DEFAULT_FLAG);
120
121bail:
122	return (dat_status);
123}
124