2 * Copyright (c) 1998,1999,2000
3 * Traakan, Inc., Los Altos, CA
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice unmodified, this list of conditions, and the following
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include "ndmagents.h"
41 #ifndef NDMOS_OPTION_NO_CONTROL_AGENT
45 ndmca_connect_xxx_agent (
46 struct ndm_session *sess,
47 struct ndmconn **connp,
49 struct ndmagent *agent)
51 struct ndmconn * conn = *connp;
56 return 0; /* already connected */
58 if (agent->conn_type == NDMCONN_TYPE_NONE) {
59 ndmalogf (sess, 0, 0, "agent %s not give", prefix+1);
63 conn = ndmconn_initialize (0, prefix);
65 ndmalogf (sess, prefix, 0, "can't init connection");
69 if (sess->control_acb.job.time_limit > 0)
70 conn->time_limit = sess->control_acb.job.time_limit;
72 ndmconn_set_snoop (conn, &sess->param.log, sess->param.log_level);
74 conn->call = ndma_call;
76 conn->unexpected = ndma_dispatch_ctrl_unexpected;
78 rc = ndmconn_connect_agent (conn, agent);
80 err = "Can't connect";
84 rc = ndmconn_auth_agent (conn, agent);
86 err = "Can't auth (bad pw?)";
94 ndmalogf (sess, prefix, 0, "err %s", ndmconn_get_err_msg (conn));
95 //ndmconn_destruct (conn);
102 ndmca_connect_data_agent (struct ndm_session *sess)
106 rc = ndmca_connect_xxx_agent (sess,
109 &sess->control_acb.job.data_agent);
111 if (sess->plumb.data->conn_type == NDMCONN_TYPE_RESIDENT) {
112 sess->data_acb.protocol_version =
113 sess->plumb.data->protocol_version;
121 ndmca_connect_tape_agent (struct ndm_session *sess)
125 if (sess->control_acb.job.tape_agent.conn_type == NDMCONN_TYPE_NONE) {
126 rc = ndmca_connect_data_agent (sess);
128 ndmconn_destruct (sess->plumb.data);
131 sess->plumb.tape = sess->plumb.data;
134 rc = ndmca_connect_xxx_agent (sess,
137 &sess->control_acb.job.tape_agent);
138 ndmalogf (sess, 0, 7, "ndmca_connect_tape_agent: %d %p", rc, sess->plumb.tape);
142 if (sess->plumb.tape->conn_type == NDMCONN_TYPE_RESIDENT) {
143 sess->tape_acb.protocol_version =
144 sess->plumb.tape->protocol_version;
152 ndmca_connect_robot_agent (struct ndm_session *sess)
156 if (sess->control_acb.job.robot_agent.conn_type == NDMCONN_TYPE_NONE) {
157 rc = ndmca_connect_tape_agent (sess);
159 sess->plumb.robot = sess->plumb.tape;
162 rc = ndmca_connect_xxx_agent (sess,
165 &sess->control_acb.job.robot_agent);
169 if (sess->plumb.robot->conn_type == NDMCONN_TYPE_RESIDENT) {
170 sess->robot_acb.protocol_version =
171 sess->plumb.robot->protocol_version;
179 ndmca_connect_control_agent (struct ndm_session *sess)
181 struct ndmagent control_agent;
184 ndmagent_from_str (&control_agent, "."); /* resident */
186 rc = ndmca_connect_xxx_agent (sess,
187 &sess->plumb.control,
194 #endif /* !NDMOS_OPTION_NO_CONTROL_AGENT */