15331Samw /*
25331Samw * CDDL HEADER START
35331Samw *
45331Samw * The contents of this file are subject to the terms of the
55331Samw * Common Development and Distribution License (the "License").
65331Samw * You may not use this file except in compliance with the License.
75331Samw *
85331Samw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95331Samw * or http://www.opensolaris.org/os/licensing.
105331Samw * See the License for the specific language governing permissions
115331Samw * and limitations under the License.
125331Samw *
135331Samw * When distributing Covered Code, include this CDDL HEADER in each
145331Samw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155331Samw * If applicable, add the following below this CDDL HEADER, with the
165331Samw * fields enclosed by brackets "[]" replaced with your own identifying
175331Samw * information: Portions Copyright [yyyy] [name of copyright owner]
185331Samw *
195331Samw * CDDL HEADER END
205331Samw */
215331Samw /*
22*11963SAfshin.Ardakani@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
235331Samw * Use is subject to license terms.
245331Samw */
255331Samw
2610966SJordan.Brown@Sun.COM #include <smbsrv/smb_kproto.h>
275331Samw
285331Samw /*
295331Samw * The echo request is used to test the connection to the server,
305331Samw * and to see if the server is still responding. The tid is ignored,
315331Samw * so this request may be sent to the server even if there are no
325331Samw * tree connections to the server.
335331Samw *
345331Samw * Each response echoes the data sent, though ByteCount may indicate
355331Samw * no data. If echo-count is zero, no response is sent.
365331Samw */
376030Sjb150015 smb_sdrc_t
smb_pre_echo(smb_request_t * sr)386139Sjb150015 smb_pre_echo(smb_request_t *sr)
396139Sjb150015 {
406139Sjb150015 DTRACE_SMB_1(op__Echo__start, smb_request_t *, sr);
416139Sjb150015 return (SDRC_SUCCESS);
426139Sjb150015 }
436139Sjb150015
446139Sjb150015 void
smb_post_echo(smb_request_t * sr)456139Sjb150015 smb_post_echo(smb_request_t *sr)
466139Sjb150015 {
476139Sjb150015 DTRACE_SMB_1(op__Echo__done, smb_request_t *, sr);
486139Sjb150015 }
496139Sjb150015
506139Sjb150015 smb_sdrc_t
smb_com_echo(struct smb_request * sr)515331Samw smb_com_echo(struct smb_request *sr)
525331Samw {
535331Samw unsigned short necho;
545331Samw unsigned short nbytes;
555331Samw unsigned short i;
565331Samw struct mbuf_chain reply;
575331Samw char *data;
585331Samw
596030Sjb150015 if (smbsr_decode_vwv(sr, "w", &necho) != 0)
606139Sjb150015 return (SDRC_ERROR);
615331Samw
625331Samw nbytes = sr->smb_bcc;
63*11963SAfshin.Ardakani@Sun.COM data = smb_srm_zalloc(sr, nbytes);
645331Samw
657052Samw if (smb_mbc_decodef(&sr->smb_data, "#c", nbytes, data))
666139Sjb150015 return (SDRC_ERROR);
675331Samw
685331Samw for (i = 1; i <= necho; ++i) {
695331Samw MBC_INIT(&reply, SMB_HEADER_ED_LEN + 10 + nbytes);
705331Samw
717052Samw (void) smb_mbc_encodef(&reply, SMB_HEADER_ED_FMT,
725331Samw sr->first_smb_com,
735331Samw sr->smb_rcls,
745331Samw sr->smb_reh,
755331Samw sr->smb_err,
765331Samw sr->smb_flg | SMB_FLAGS_REPLY,
775331Samw sr->smb_flg2,
785331Samw sr->smb_pid_high,
795331Samw sr->smb_sig,
805331Samw sr->smb_tid,
815331Samw sr->smb_pid,
825331Samw sr->smb_uid,
835331Samw sr->smb_mid);
845331Samw
857052Samw (void) smb_mbc_encodef(&reply, "bww#c", 1, i,
865331Samw nbytes, nbytes, data);
875331Samw
885331Samw if (sr->session->signing.flags & SMB_SIGNING_ENABLED)
895331Samw smb_sign_reply(sr, &reply);
905331Samw
915331Samw (void) smb_session_send(sr->session, 0, &reply);
925331Samw }
935331Samw
945331Samw return (SDRC_NO_REPLY);
955331Samw }
96