kernel: use ddi_msleep() instead of delay(drv_usectohz(x))
[unleashed.git] / usr / src / uts / common / fs / smbsrv / smb_echo.c
blob81fa6c2729266d3bdee59d52b0d26cec6aaa9b45
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
25 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
28 #include <smbsrv/smb_kproto.h>
31 * The echo request is used to test the connection to the server,
32 * and to see if the server is still responding. The tid is ignored,
33 * so this request may be sent to the server even if there are no
34 * tree connections to the server.
36 * Each response echoes the data sent, though ByteCount may indicate
37 * no data. If echo-count is zero, no response is sent.
39 smb_sdrc_t
40 smb_pre_echo(smb_request_t *sr)
42 DTRACE_SMB_1(op__Echo__start, smb_request_t *, sr);
43 return (SDRC_SUCCESS);
46 void
47 smb_post_echo(smb_request_t *sr)
49 DTRACE_SMB_1(op__Echo__done, smb_request_t *, sr);
52 static unsigned short smb_max_echo = 10;
54 smb_sdrc_t
55 smb_com_echo(struct smb_request *sr)
57 unsigned short necho;
58 unsigned short nbytes;
59 unsigned short i;
60 struct mbuf_chain reply;
61 char *data;
62 uint16_t pid_hi, pid_lo;
64 pid_hi = sr->smb_pid >> 16;
65 pid_lo = (uint16_t)sr->smb_pid;
67 if (smbsr_decode_vwv(sr, "w", &necho) != 0)
68 return (SDRC_ERROR);
71 * Don't let the client fool us into doing
72 * more work than is "reasonable".
74 if (necho > smb_max_echo)
75 necho = smb_max_echo;
77 nbytes = sr->smb_bcc;
78 data = smb_srm_zalloc(sr, nbytes);
80 if (smb_mbc_decodef(&sr->smb_data, "#c", nbytes, data))
81 return (SDRC_ERROR);
83 for (i = 1; i <= necho; ++i) {
86 * According to [MS-CIFS] 3.3.5.32 echo is
87 * subject to cancellation.
89 if (sr->sr_state != SMB_REQ_STATE_ACTIVE)
90 break;
92 MBC_INIT(&reply, SMB_HEADER_ED_LEN + 10 + nbytes);
94 (void) smb_mbc_encodef(&reply, SMB_HEADER_ED_FMT,
95 sr->first_smb_com,
96 sr->smb_rcls,
97 sr->smb_reh,
98 sr->smb_err,
99 sr->smb_flg | SMB_FLAGS_REPLY,
100 sr->smb_flg2,
101 pid_hi,
102 sr->smb_sig,
103 sr->smb_tid,
104 pid_lo,
105 sr->smb_uid,
106 sr->smb_mid);
108 (void) smb_mbc_encodef(&reply, "bww#c", 1, i,
109 nbytes, nbytes, data);
111 if (sr->session->signing.flags & SMB_SIGNING_ENABLED)
112 smb_sign_reply(sr, &reply);
114 (void) smb_session_send(sr->session, 0, &reply);
116 ddi_msleep(100);
119 return (SDRC_NO_REPLY);