162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *   Copyright (C) 2016 Namjae Jeon <linkinjeon@kernel.org>
462306a36Sopenharmony_ci *   Copyright (C) 2018 Samsung Electronics Co., Ltd.
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#ifndef _SMB2PDU_H
862306a36Sopenharmony_ci#define _SMB2PDU_H
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include "ntlmssp.h"
1162306a36Sopenharmony_ci#include "smbacl.h"
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci/*Create Action Flags*/
1462306a36Sopenharmony_ci#define FILE_SUPERSEDED                0x00000000
1562306a36Sopenharmony_ci#define FILE_OPENED            0x00000001
1662306a36Sopenharmony_ci#define FILE_CREATED           0x00000002
1762306a36Sopenharmony_ci#define FILE_OVERWRITTEN       0x00000003
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci/* SMB2 Max Credits */
2062306a36Sopenharmony_ci#define SMB2_MAX_CREDITS		8192
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci/* BB FIXME - analyze following length BB */
2362306a36Sopenharmony_ci#define MAX_SMB2_HDR_SIZE 0x78 /* 4 len + 64 hdr + (2*24 wct) + 2 bct + 2 pad */
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci#define SMB21_DEFAULT_IOSIZE	(1024 * 1024)
2662306a36Sopenharmony_ci#define SMB3_DEFAULT_TRANS_SIZE	(1024 * 1024)
2762306a36Sopenharmony_ci#define SMB3_MIN_IOSIZE		(64 * 1024)
2862306a36Sopenharmony_ci#define SMB3_MAX_IOSIZE		(8 * 1024 * 1024)
2962306a36Sopenharmony_ci#define SMB3_MAX_MSGSIZE	(4 * 4096)
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci/*
3262306a36Sopenharmony_ci *	Definitions for SMB2 Protocol Data Units (network frames)
3362306a36Sopenharmony_ci *
3462306a36Sopenharmony_ci *  See MS-SMB2.PDF specification for protocol details.
3562306a36Sopenharmony_ci *  The Naming convention is the lower case version of the SMB2
3662306a36Sopenharmony_ci *  command code name for the struct. Note that structures must be packed.
3762306a36Sopenharmony_ci *
3862306a36Sopenharmony_ci */
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_cistruct preauth_integrity_info {
4162306a36Sopenharmony_ci	/* PreAuth integrity Hash ID */
4262306a36Sopenharmony_ci	__le16			Preauth_HashId;
4362306a36Sopenharmony_ci	/* PreAuth integrity Hash Value */
4462306a36Sopenharmony_ci	__u8			Preauth_HashValue[SMB2_PREAUTH_HASH_SIZE];
4562306a36Sopenharmony_ci};
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci/* offset is sizeof smb2_negotiate_rsp but rounded up to 8 bytes. */
4862306a36Sopenharmony_ci#ifdef CONFIG_SMB_SERVER_KERBEROS5
4962306a36Sopenharmony_ci/* sizeof(struct smb2_negotiate_rsp) =
5062306a36Sopenharmony_ci * header(64) + response(64) + GSS_LENGTH(96) + GSS_PADDING(0)
5162306a36Sopenharmony_ci */
5262306a36Sopenharmony_ci#define OFFSET_OF_NEG_CONTEXT	0xe0
5362306a36Sopenharmony_ci#else
5462306a36Sopenharmony_ci/* sizeof(struct smb2_negotiate_rsp) =
5562306a36Sopenharmony_ci * header(64) + response(64) + GSS_LENGTH(74) + GSS_PADDING(6)
5662306a36Sopenharmony_ci */
5762306a36Sopenharmony_ci#define OFFSET_OF_NEG_CONTEXT	0xd0
5862306a36Sopenharmony_ci#endif
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci#define SMB2_SESSION_EXPIRED		(0)
6162306a36Sopenharmony_ci#define SMB2_SESSION_IN_PROGRESS	BIT(0)
6262306a36Sopenharmony_ci#define SMB2_SESSION_VALID		BIT(1)
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci#define SMB2_SESSION_TIMEOUT		(10 * HZ)
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_cistruct create_durable_req_v2 {
6762306a36Sopenharmony_ci	struct create_context ccontext;
6862306a36Sopenharmony_ci	__u8   Name[8];
6962306a36Sopenharmony_ci	__le32 Timeout;
7062306a36Sopenharmony_ci	__le32 Flags;
7162306a36Sopenharmony_ci	__u8 Reserved[8];
7262306a36Sopenharmony_ci	__u8 CreateGuid[16];
7362306a36Sopenharmony_ci} __packed;
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_cistruct create_durable_reconn_v2_req {
7662306a36Sopenharmony_ci	struct create_context ccontext;
7762306a36Sopenharmony_ci	__u8   Name[8];
7862306a36Sopenharmony_ci	struct {
7962306a36Sopenharmony_ci		__u64 PersistentFileId;
8062306a36Sopenharmony_ci		__u64 VolatileFileId;
8162306a36Sopenharmony_ci	} Fid;
8262306a36Sopenharmony_ci	__u8 CreateGuid[16];
8362306a36Sopenharmony_ci	__le32 Flags;
8462306a36Sopenharmony_ci} __packed;
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_cistruct create_alloc_size_req {
8762306a36Sopenharmony_ci	struct create_context ccontext;
8862306a36Sopenharmony_ci	__u8   Name[8];
8962306a36Sopenharmony_ci	__le64 AllocationSize;
9062306a36Sopenharmony_ci} __packed;
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_cistruct create_durable_rsp {
9362306a36Sopenharmony_ci	struct create_context ccontext;
9462306a36Sopenharmony_ci	__u8   Name[8];
9562306a36Sopenharmony_ci	union {
9662306a36Sopenharmony_ci		__u8  Reserved[8];
9762306a36Sopenharmony_ci		__u64 data;
9862306a36Sopenharmony_ci	} Data;
9962306a36Sopenharmony_ci} __packed;
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_cistruct create_durable_v2_rsp {
10262306a36Sopenharmony_ci	struct create_context ccontext;
10362306a36Sopenharmony_ci	__u8   Name[8];
10462306a36Sopenharmony_ci	__le32 Timeout;
10562306a36Sopenharmony_ci	__le32 Flags;
10662306a36Sopenharmony_ci} __packed;
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci/* equivalent of the contents of SMB3.1.1 POSIX open context response */
10962306a36Sopenharmony_cistruct create_posix_rsp {
11062306a36Sopenharmony_ci	struct create_context ccontext;
11162306a36Sopenharmony_ci	__u8    Name[16];
11262306a36Sopenharmony_ci	__le32 nlink;
11362306a36Sopenharmony_ci	__le32 reparse_tag;
11462306a36Sopenharmony_ci	__le32 mode;
11562306a36Sopenharmony_ci	/* SidBuffer contain two sids(Domain sid(28), UNIX group sid(16)) */
11662306a36Sopenharmony_ci	u8 SidBuffer[44];
11762306a36Sopenharmony_ci} __packed;
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_cistruct smb2_buffer_desc_v1 {
12062306a36Sopenharmony_ci	__le64 offset;
12162306a36Sopenharmony_ci	__le32 token;
12262306a36Sopenharmony_ci	__le32 length;
12362306a36Sopenharmony_ci} __packed;
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci#define SMB2_0_IOCTL_IS_FSCTL 0x00000001
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_cistruct smb_sockaddr_in {
12862306a36Sopenharmony_ci	__be16 Port;
12962306a36Sopenharmony_ci	__be32 IPv4address;
13062306a36Sopenharmony_ci	__u8 Reserved[8];
13162306a36Sopenharmony_ci} __packed;
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_cistruct smb_sockaddr_in6 {
13462306a36Sopenharmony_ci	__be16 Port;
13562306a36Sopenharmony_ci	__be32 FlowInfo;
13662306a36Sopenharmony_ci	__u8 IPv6address[16];
13762306a36Sopenharmony_ci	__be32 ScopeId;
13862306a36Sopenharmony_ci} __packed;
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci#define INTERNETWORK	0x0002
14162306a36Sopenharmony_ci#define INTERNETWORKV6	0x0017
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_cistruct sockaddr_storage_rsp {
14462306a36Sopenharmony_ci	__le16 Family;
14562306a36Sopenharmony_ci	union {
14662306a36Sopenharmony_ci		struct smb_sockaddr_in addr4;
14762306a36Sopenharmony_ci		struct smb_sockaddr_in6 addr6;
14862306a36Sopenharmony_ci	};
14962306a36Sopenharmony_ci} __packed;
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci#define RSS_CAPABLE	0x00000001
15262306a36Sopenharmony_ci#define RDMA_CAPABLE	0x00000002
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_cistruct network_interface_info_ioctl_rsp {
15562306a36Sopenharmony_ci	__le32 Next; /* next interface. zero if this is last one */
15662306a36Sopenharmony_ci	__le32 IfIndex;
15762306a36Sopenharmony_ci	__le32 Capability; /* RSS or RDMA Capable */
15862306a36Sopenharmony_ci	__le32 Reserved;
15962306a36Sopenharmony_ci	__le64 LinkSpeed;
16062306a36Sopenharmony_ci	char	SockAddr_Storage[128];
16162306a36Sopenharmony_ci} __packed;
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_cistruct file_object_buf_type1_ioctl_rsp {
16462306a36Sopenharmony_ci	__u8 ObjectId[16];
16562306a36Sopenharmony_ci	__u8 BirthVolumeId[16];
16662306a36Sopenharmony_ci	__u8 BirthObjectId[16];
16762306a36Sopenharmony_ci	__u8 DomainId[16];
16862306a36Sopenharmony_ci} __packed;
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_cistruct resume_key_ioctl_rsp {
17162306a36Sopenharmony_ci	__u64 ResumeKey[3];
17262306a36Sopenharmony_ci	__le32 ContextLength;
17362306a36Sopenharmony_ci	__u8 Context[4]; /* ignored, Windows sets to 4 bytes of zero */
17462306a36Sopenharmony_ci} __packed;
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_cistruct copychunk_ioctl_req {
17762306a36Sopenharmony_ci	__le64 ResumeKey[3];
17862306a36Sopenharmony_ci	__le32 ChunkCount;
17962306a36Sopenharmony_ci	__le32 Reserved;
18062306a36Sopenharmony_ci	__u8 Chunks[1]; /* array of srv_copychunk */
18162306a36Sopenharmony_ci} __packed;
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_cistruct srv_copychunk {
18462306a36Sopenharmony_ci	__le64 SourceOffset;
18562306a36Sopenharmony_ci	__le64 TargetOffset;
18662306a36Sopenharmony_ci	__le32 Length;
18762306a36Sopenharmony_ci	__le32 Reserved;
18862306a36Sopenharmony_ci} __packed;
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_cistruct copychunk_ioctl_rsp {
19162306a36Sopenharmony_ci	__le32 ChunksWritten;
19262306a36Sopenharmony_ci	__le32 ChunkBytesWritten;
19362306a36Sopenharmony_ci	__le32 TotalBytesWritten;
19462306a36Sopenharmony_ci} __packed;
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_cistruct file_sparse {
19762306a36Sopenharmony_ci	__u8	SetSparse;
19862306a36Sopenharmony_ci} __packed;
19962306a36Sopenharmony_ci
20062306a36Sopenharmony_ci/* FILE Info response size */
20162306a36Sopenharmony_ci#define FILE_DIRECTORY_INFORMATION_SIZE       1
20262306a36Sopenharmony_ci#define FILE_FULL_DIRECTORY_INFORMATION_SIZE  2
20362306a36Sopenharmony_ci#define FILE_BOTH_DIRECTORY_INFORMATION_SIZE  3
20462306a36Sopenharmony_ci#define FILE_BASIC_INFORMATION_SIZE           40
20562306a36Sopenharmony_ci#define FILE_STANDARD_INFORMATION_SIZE        24
20662306a36Sopenharmony_ci#define FILE_INTERNAL_INFORMATION_SIZE        8
20762306a36Sopenharmony_ci#define FILE_EA_INFORMATION_SIZE              4
20862306a36Sopenharmony_ci#define FILE_ACCESS_INFORMATION_SIZE          4
20962306a36Sopenharmony_ci#define FILE_NAME_INFORMATION_SIZE            9
21062306a36Sopenharmony_ci#define FILE_RENAME_INFORMATION_SIZE          10
21162306a36Sopenharmony_ci#define FILE_LINK_INFORMATION_SIZE            11
21262306a36Sopenharmony_ci#define FILE_NAMES_INFORMATION_SIZE           12
21362306a36Sopenharmony_ci#define FILE_DISPOSITION_INFORMATION_SIZE     13
21462306a36Sopenharmony_ci#define FILE_POSITION_INFORMATION_SIZE        14
21562306a36Sopenharmony_ci#define FILE_FULL_EA_INFORMATION_SIZE         15
21662306a36Sopenharmony_ci#define FILE_MODE_INFORMATION_SIZE            4
21762306a36Sopenharmony_ci#define FILE_ALIGNMENT_INFORMATION_SIZE       4
21862306a36Sopenharmony_ci#define FILE_ALL_INFORMATION_SIZE             104
21962306a36Sopenharmony_ci#define FILE_ALLOCATION_INFORMATION_SIZE      19
22062306a36Sopenharmony_ci#define FILE_END_OF_FILE_INFORMATION_SIZE     20
22162306a36Sopenharmony_ci#define FILE_ALTERNATE_NAME_INFORMATION_SIZE  8
22262306a36Sopenharmony_ci#define FILE_STREAM_INFORMATION_SIZE          32
22362306a36Sopenharmony_ci#define FILE_PIPE_INFORMATION_SIZE            23
22462306a36Sopenharmony_ci#define FILE_PIPE_LOCAL_INFORMATION_SIZE      24
22562306a36Sopenharmony_ci#define FILE_PIPE_REMOTE_INFORMATION_SIZE     25
22662306a36Sopenharmony_ci#define FILE_MAILSLOT_QUERY_INFORMATION_SIZE  26
22762306a36Sopenharmony_ci#define FILE_MAILSLOT_SET_INFORMATION_SIZE    27
22862306a36Sopenharmony_ci#define FILE_COMPRESSION_INFORMATION_SIZE     16
22962306a36Sopenharmony_ci#define FILE_OBJECT_ID_INFORMATION_SIZE       29
23062306a36Sopenharmony_ci/* Number 30 not defined in documents */
23162306a36Sopenharmony_ci#define FILE_MOVE_CLUSTER_INFORMATION_SIZE    31
23262306a36Sopenharmony_ci#define FILE_QUOTA_INFORMATION_SIZE           32
23362306a36Sopenharmony_ci#define FILE_REPARSE_POINT_INFORMATION_SIZE   33
23462306a36Sopenharmony_ci#define FILE_NETWORK_OPEN_INFORMATION_SIZE    56
23562306a36Sopenharmony_ci#define FILE_ATTRIBUTE_TAG_INFORMATION_SIZE   8
23662306a36Sopenharmony_ci
23762306a36Sopenharmony_ci/* FS Info response  size */
23862306a36Sopenharmony_ci#define FS_DEVICE_INFORMATION_SIZE     8
23962306a36Sopenharmony_ci#define FS_ATTRIBUTE_INFORMATION_SIZE  16
24062306a36Sopenharmony_ci#define FS_VOLUME_INFORMATION_SIZE     24
24162306a36Sopenharmony_ci#define FS_SIZE_INFORMATION_SIZE       24
24262306a36Sopenharmony_ci#define FS_FULL_SIZE_INFORMATION_SIZE  32
24362306a36Sopenharmony_ci#define FS_SECTOR_SIZE_INFORMATION_SIZE 28
24462306a36Sopenharmony_ci#define FS_OBJECT_ID_INFORMATION_SIZE 64
24562306a36Sopenharmony_ci#define FS_CONTROL_INFORMATION_SIZE 48
24662306a36Sopenharmony_ci#define FS_POSIX_INFORMATION_SIZE 56
24762306a36Sopenharmony_ci
24862306a36Sopenharmony_ci/* FS_ATTRIBUTE_File_System_Name */
24962306a36Sopenharmony_ci#define FS_TYPE_SUPPORT_SIZE   44
25062306a36Sopenharmony_cistruct fs_type_info {
25162306a36Sopenharmony_ci	char		*fs_name;
25262306a36Sopenharmony_ci	long		magic_number;
25362306a36Sopenharmony_ci} __packed;
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_ci/*
25662306a36Sopenharmony_ci *	PDU query infolevel structure definitions
25762306a36Sopenharmony_ci *	BB consider moving to a different header
25862306a36Sopenharmony_ci */
25962306a36Sopenharmony_ci
26062306a36Sopenharmony_cistruct smb2_file_access_info {
26162306a36Sopenharmony_ci	__le32 AccessFlags;
26262306a36Sopenharmony_ci} __packed;
26362306a36Sopenharmony_ci
26462306a36Sopenharmony_cistruct smb2_file_alignment_info {
26562306a36Sopenharmony_ci	__le32 AlignmentRequirement;
26662306a36Sopenharmony_ci} __packed;
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_cistruct smb2_file_basic_info { /* data block encoding of response to level 18 */
26962306a36Sopenharmony_ci	__le64 CreationTime;	/* Beginning of FILE_BASIC_INFO equivalent */
27062306a36Sopenharmony_ci	__le64 LastAccessTime;
27162306a36Sopenharmony_ci	__le64 LastWriteTime;
27262306a36Sopenharmony_ci	__le64 ChangeTime;
27362306a36Sopenharmony_ci	__le32 Attributes;
27462306a36Sopenharmony_ci	__u32  Pad1;		/* End of FILE_BASIC_INFO_INFO equivalent */
27562306a36Sopenharmony_ci} __packed;
27662306a36Sopenharmony_ci
27762306a36Sopenharmony_cistruct smb2_file_alt_name_info {
27862306a36Sopenharmony_ci	__le32 FileNameLength;
27962306a36Sopenharmony_ci	char FileName[];
28062306a36Sopenharmony_ci} __packed;
28162306a36Sopenharmony_ci
28262306a36Sopenharmony_cistruct smb2_file_stream_info {
28362306a36Sopenharmony_ci	__le32  NextEntryOffset;
28462306a36Sopenharmony_ci	__le32  StreamNameLength;
28562306a36Sopenharmony_ci	__le64 StreamSize;
28662306a36Sopenharmony_ci	__le64 StreamAllocationSize;
28762306a36Sopenharmony_ci	char   StreamName[];
28862306a36Sopenharmony_ci} __packed;
28962306a36Sopenharmony_ci
29062306a36Sopenharmony_cistruct smb2_file_ntwrk_info {
29162306a36Sopenharmony_ci	__le64 CreationTime;
29262306a36Sopenharmony_ci	__le64 LastAccessTime;
29362306a36Sopenharmony_ci	__le64 LastWriteTime;
29462306a36Sopenharmony_ci	__le64 ChangeTime;
29562306a36Sopenharmony_ci	__le64 AllocationSize;
29662306a36Sopenharmony_ci	__le64 EndOfFile;
29762306a36Sopenharmony_ci	__le32 Attributes;
29862306a36Sopenharmony_ci	__le32 Reserved;
29962306a36Sopenharmony_ci} __packed;
30062306a36Sopenharmony_ci
30162306a36Sopenharmony_cistruct smb2_file_standard_info {
30262306a36Sopenharmony_ci	__le64 AllocationSize;
30362306a36Sopenharmony_ci	__le64 EndOfFile;
30462306a36Sopenharmony_ci	__le32 NumberOfLinks;	/* hard links */
30562306a36Sopenharmony_ci	__u8   DeletePending;
30662306a36Sopenharmony_ci	__u8   Directory;
30762306a36Sopenharmony_ci	__le16 Reserved;
30862306a36Sopenharmony_ci} __packed; /* level 18 Query */
30962306a36Sopenharmony_ci
31062306a36Sopenharmony_cistruct smb2_file_ea_info {
31162306a36Sopenharmony_ci	__le32 EASize;
31262306a36Sopenharmony_ci} __packed;
31362306a36Sopenharmony_ci
31462306a36Sopenharmony_cistruct smb2_file_alloc_info {
31562306a36Sopenharmony_ci	__le64 AllocationSize;
31662306a36Sopenharmony_ci} __packed;
31762306a36Sopenharmony_ci
31862306a36Sopenharmony_cistruct smb2_file_disposition_info {
31962306a36Sopenharmony_ci	__u8 DeletePending;
32062306a36Sopenharmony_ci} __packed;
32162306a36Sopenharmony_ci
32262306a36Sopenharmony_cistruct smb2_file_pos_info {
32362306a36Sopenharmony_ci	__le64 CurrentByteOffset;
32462306a36Sopenharmony_ci} __packed;
32562306a36Sopenharmony_ci
32662306a36Sopenharmony_ci#define FILE_MODE_INFO_MASK cpu_to_le32(0x0000100e)
32762306a36Sopenharmony_ci
32862306a36Sopenharmony_cistruct smb2_file_mode_info {
32962306a36Sopenharmony_ci	__le32 Mode;
33062306a36Sopenharmony_ci} __packed;
33162306a36Sopenharmony_ci
33262306a36Sopenharmony_ci#define COMPRESSION_FORMAT_NONE 0x0000
33362306a36Sopenharmony_ci#define COMPRESSION_FORMAT_LZNT1 0x0002
33462306a36Sopenharmony_ci
33562306a36Sopenharmony_cistruct smb2_file_comp_info {
33662306a36Sopenharmony_ci	__le64 CompressedFileSize;
33762306a36Sopenharmony_ci	__le16 CompressionFormat;
33862306a36Sopenharmony_ci	__u8 CompressionUnitShift;
33962306a36Sopenharmony_ci	__u8 ChunkShift;
34062306a36Sopenharmony_ci	__u8 ClusterShift;
34162306a36Sopenharmony_ci	__u8 Reserved[3];
34262306a36Sopenharmony_ci} __packed;
34362306a36Sopenharmony_ci
34462306a36Sopenharmony_cistruct smb2_file_attr_tag_info {
34562306a36Sopenharmony_ci	__le32 FileAttributes;
34662306a36Sopenharmony_ci	__le32 ReparseTag;
34762306a36Sopenharmony_ci} __packed;
34862306a36Sopenharmony_ci
34962306a36Sopenharmony_ci#define SL_RESTART_SCAN	0x00000001
35062306a36Sopenharmony_ci#define SL_RETURN_SINGLE_ENTRY	0x00000002
35162306a36Sopenharmony_ci#define SL_INDEX_SPECIFIED	0x00000004
35262306a36Sopenharmony_ci
35362306a36Sopenharmony_cistruct smb2_ea_info_req {
35462306a36Sopenharmony_ci	__le32 NextEntryOffset;
35562306a36Sopenharmony_ci	__u8   EaNameLength;
35662306a36Sopenharmony_ci	char name[1];
35762306a36Sopenharmony_ci} __packed; /* level 15 Query */
35862306a36Sopenharmony_ci
35962306a36Sopenharmony_cistruct smb2_ea_info {
36062306a36Sopenharmony_ci	__le32 NextEntryOffset;
36162306a36Sopenharmony_ci	__u8   Flags;
36262306a36Sopenharmony_ci	__u8   EaNameLength;
36362306a36Sopenharmony_ci	__le16 EaValueLength;
36462306a36Sopenharmony_ci	char name[];
36562306a36Sopenharmony_ci	/* optionally followed by value */
36662306a36Sopenharmony_ci} __packed; /* level 15 Query */
36762306a36Sopenharmony_ci
36862306a36Sopenharmony_cistruct create_ea_buf_req {
36962306a36Sopenharmony_ci	struct create_context ccontext;
37062306a36Sopenharmony_ci	__u8   Name[8];
37162306a36Sopenharmony_ci	struct smb2_ea_info ea;
37262306a36Sopenharmony_ci} __packed;
37362306a36Sopenharmony_ci
37462306a36Sopenharmony_cistruct create_sd_buf_req {
37562306a36Sopenharmony_ci	struct create_context ccontext;
37662306a36Sopenharmony_ci	__u8   Name[8];
37762306a36Sopenharmony_ci	struct smb_ntsd ntsd;
37862306a36Sopenharmony_ci} __packed;
37962306a36Sopenharmony_ci
38062306a36Sopenharmony_cistruct smb2_posix_info {
38162306a36Sopenharmony_ci	__le32 NextEntryOffset;
38262306a36Sopenharmony_ci	__u32 Ignored;
38362306a36Sopenharmony_ci	__le64 CreationTime;
38462306a36Sopenharmony_ci	__le64 LastAccessTime;
38562306a36Sopenharmony_ci	__le64 LastWriteTime;
38662306a36Sopenharmony_ci	__le64 ChangeTime;
38762306a36Sopenharmony_ci	__le64 EndOfFile;
38862306a36Sopenharmony_ci	__le64 AllocationSize;
38962306a36Sopenharmony_ci	__le32 DosAttributes;
39062306a36Sopenharmony_ci	__le64 Inode;
39162306a36Sopenharmony_ci	__le32 DeviceId;
39262306a36Sopenharmony_ci	__le32 Zero;
39362306a36Sopenharmony_ci	/* beginning of POSIX Create Context Response */
39462306a36Sopenharmony_ci	__le32 HardLinks;
39562306a36Sopenharmony_ci	__le32 ReparseTag;
39662306a36Sopenharmony_ci	__le32 Mode;
39762306a36Sopenharmony_ci	/* SidBuffer contain two sids (UNIX user sid(16), UNIX group sid(16)) */
39862306a36Sopenharmony_ci	u8 SidBuffer[32];
39962306a36Sopenharmony_ci	__le32 name_len;
40062306a36Sopenharmony_ci	u8 name[];
40162306a36Sopenharmony_ci	/*
40262306a36Sopenharmony_ci	 * var sized owner SID
40362306a36Sopenharmony_ci	 * var sized group SID
40462306a36Sopenharmony_ci	 * le32 filenamelength
40562306a36Sopenharmony_ci	 * u8  filename[]
40662306a36Sopenharmony_ci	 */
40762306a36Sopenharmony_ci} __packed;
40862306a36Sopenharmony_ci
40962306a36Sopenharmony_ci/* functions */
41062306a36Sopenharmony_civoid init_smb2_1_server(struct ksmbd_conn *conn);
41162306a36Sopenharmony_civoid init_smb3_0_server(struct ksmbd_conn *conn);
41262306a36Sopenharmony_civoid init_smb3_02_server(struct ksmbd_conn *conn);
41362306a36Sopenharmony_ciint init_smb3_11_server(struct ksmbd_conn *conn);
41462306a36Sopenharmony_ci
41562306a36Sopenharmony_civoid init_smb2_max_read_size(unsigned int sz);
41662306a36Sopenharmony_civoid init_smb2_max_write_size(unsigned int sz);
41762306a36Sopenharmony_civoid init_smb2_max_trans_size(unsigned int sz);
41862306a36Sopenharmony_civoid init_smb2_max_credits(unsigned int sz);
41962306a36Sopenharmony_ci
42062306a36Sopenharmony_cibool is_smb2_neg_cmd(struct ksmbd_work *work);
42162306a36Sopenharmony_cibool is_smb2_rsp(struct ksmbd_work *work);
42262306a36Sopenharmony_ci
42362306a36Sopenharmony_ciu16 get_smb2_cmd_val(struct ksmbd_work *work);
42462306a36Sopenharmony_civoid set_smb2_rsp_status(struct ksmbd_work *work, __le32 err);
42562306a36Sopenharmony_ciint init_smb2_rsp_hdr(struct ksmbd_work *work);
42662306a36Sopenharmony_ciint smb2_allocate_rsp_buf(struct ksmbd_work *work);
42762306a36Sopenharmony_cibool is_chained_smb2_message(struct ksmbd_work *work);
42862306a36Sopenharmony_ciint init_smb2_neg_rsp(struct ksmbd_work *work);
42962306a36Sopenharmony_civoid smb2_set_err_rsp(struct ksmbd_work *work);
43062306a36Sopenharmony_ciint smb2_check_user_session(struct ksmbd_work *work);
43162306a36Sopenharmony_ciint smb2_get_ksmbd_tcon(struct ksmbd_work *work);
43262306a36Sopenharmony_cibool smb2_is_sign_req(struct ksmbd_work *work, unsigned int command);
43362306a36Sopenharmony_ciint smb2_check_sign_req(struct ksmbd_work *work);
43462306a36Sopenharmony_civoid smb2_set_sign_rsp(struct ksmbd_work *work);
43562306a36Sopenharmony_ciint smb3_check_sign_req(struct ksmbd_work *work);
43662306a36Sopenharmony_civoid smb3_set_sign_rsp(struct ksmbd_work *work);
43762306a36Sopenharmony_ciint find_matching_smb2_dialect(int start_index, __le16 *cli_dialects,
43862306a36Sopenharmony_ci			       __le16 dialects_count);
43962306a36Sopenharmony_cistruct file_lock *smb_flock_init(struct file *f);
44062306a36Sopenharmony_ciint setup_async_work(struct ksmbd_work *work, void (*fn)(void **),
44162306a36Sopenharmony_ci		     void **arg);
44262306a36Sopenharmony_civoid release_async_work(struct ksmbd_work *work);
44362306a36Sopenharmony_civoid smb2_send_interim_resp(struct ksmbd_work *work, __le32 status);
44462306a36Sopenharmony_cistruct channel *lookup_chann_list(struct ksmbd_session *sess,
44562306a36Sopenharmony_ci				  struct ksmbd_conn *conn);
44662306a36Sopenharmony_civoid smb3_preauth_hash_rsp(struct ksmbd_work *work);
44762306a36Sopenharmony_cibool smb3_is_transform_hdr(void *buf);
44862306a36Sopenharmony_ciint smb3_decrypt_req(struct ksmbd_work *work);
44962306a36Sopenharmony_ciint smb3_encrypt_resp(struct ksmbd_work *work);
45062306a36Sopenharmony_cibool smb3_11_final_sess_setup_resp(struct ksmbd_work *work);
45162306a36Sopenharmony_ciint smb2_set_rsp_credits(struct ksmbd_work *work);
45262306a36Sopenharmony_cibool smb3_encryption_negotiated(struct ksmbd_conn *conn);
45362306a36Sopenharmony_ci
45462306a36Sopenharmony_ci/* smb2 misc functions */
45562306a36Sopenharmony_ciint ksmbd_smb2_check_message(struct ksmbd_work *work);
45662306a36Sopenharmony_ci
45762306a36Sopenharmony_ci/* smb2 command handlers */
45862306a36Sopenharmony_ciint smb2_handle_negotiate(struct ksmbd_work *work);
45962306a36Sopenharmony_ciint smb2_negotiate_request(struct ksmbd_work *work);
46062306a36Sopenharmony_ciint smb2_sess_setup(struct ksmbd_work *work);
46162306a36Sopenharmony_ciint smb2_tree_connect(struct ksmbd_work *work);
46262306a36Sopenharmony_ciint smb2_tree_disconnect(struct ksmbd_work *work);
46362306a36Sopenharmony_ciint smb2_session_logoff(struct ksmbd_work *work);
46462306a36Sopenharmony_ciint smb2_open(struct ksmbd_work *work);
46562306a36Sopenharmony_ciint smb2_query_info(struct ksmbd_work *work);
46662306a36Sopenharmony_ciint smb2_query_dir(struct ksmbd_work *work);
46762306a36Sopenharmony_ciint smb2_close(struct ksmbd_work *work);
46862306a36Sopenharmony_ciint smb2_echo(struct ksmbd_work *work);
46962306a36Sopenharmony_ciint smb2_set_info(struct ksmbd_work *work);
47062306a36Sopenharmony_ciint smb2_read(struct ksmbd_work *work);
47162306a36Sopenharmony_ciint smb2_write(struct ksmbd_work *work);
47262306a36Sopenharmony_ciint smb2_flush(struct ksmbd_work *work);
47362306a36Sopenharmony_ciint smb2_cancel(struct ksmbd_work *work);
47462306a36Sopenharmony_ciint smb2_lock(struct ksmbd_work *work);
47562306a36Sopenharmony_ciint smb2_ioctl(struct ksmbd_work *work);
47662306a36Sopenharmony_ciint smb2_oplock_break(struct ksmbd_work *work);
47762306a36Sopenharmony_ciint smb2_notify(struct ksmbd_work *ksmbd_work);
47862306a36Sopenharmony_ci
47962306a36Sopenharmony_ci/*
48062306a36Sopenharmony_ci * Get the body of the smb2 message excluding the 4 byte rfc1002 headers
48162306a36Sopenharmony_ci * from request/response buffer.
48262306a36Sopenharmony_ci */
48362306a36Sopenharmony_cistatic inline void *smb2_get_msg(void *buf)
48462306a36Sopenharmony_ci{
48562306a36Sopenharmony_ci	return buf + 4;
48662306a36Sopenharmony_ci}
48762306a36Sopenharmony_ci
48862306a36Sopenharmony_ci#endif	/* _SMB2PDU_H */
489