sdk-world v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Loading...
Searching...
No Matches
smb.h
Go to the documentation of this file.
1/*
2 Copyright 2009-2010, jimmikaelkael
3 Licenced under Academic Free License version 3.0
4*/
5
10#ifndef __SMB_H__
11#define __SMB_H__
12
13#include "ps2smb.h"
14
15#define SMB_MAGIC 0x424d53ff
16
17// SMB Headers are always 32 bytes long
18#define SMB_HDR_SIZE 32
19
20// FLAGS field bitmasks
21#define SMB_FLAGS_SERVER_TO_REDIR 0x80
22#define SMB_FLAGS_REQUEST_BATCH_OPLOCK 0x40
23#define SMB_FLAGS_REQUEST_OPLOCK 0x20
24#define SMB_FLAGS_CANONICAL_PATHNAMES 0x10
25#define SMB_FLAGS_CASELESS_PATHNAMES 0x08
26#define SMB_FLAGS_RESERVED 0x04
27#define SMB_FLAGS_CLIENT_BUF_AVAIL 0x02
28#define SMB_FLAGS_SUPPORT_LOCKREAD 0x01
29#define SMB_FLAGS_MASK 0x00
30
31// FLAGS2 field bitmasks
32#define SMB_FLAGS2_UNICODE_STRING 0x8000
33#define SMB_FLAGS2_32BIT_STATUS 0x4000
34#define SMB_FLAGS2_READ_IF_EXECUTE 0x2000
35#define SMB_FLAGS2_DFS_PATHNAME 0x1000
36#define SMB_FLAGS2_EXTENDED_SECURITY 0x0800
37#define SMB_FLAGS2_RESERVED_01 0x0400
38#define SMB_FLAGS2_RESERVED_02 0x0200
39#define SMB_FLAGS2_RESERVED_03 0x0100
40#define SMB_FLAGS2_RESERVED_04 0x0080
41#define SMB_FLAGS2_IS_LONG_NAME 0x0040
42#define SMB_FLAGS2_RESERVED_05 0x0020
43#define SMB_FLAGS2_RESERVED_06 0x0010
44#define SMB_FLAGS2_RESERVED_07 0x0008
45#define SMB_FLAGS2_SECURITY_SIGNATURE 0x0004
46#define SMB_FLAGS2_EAS 0x0002
47#define SMB_FLAGS2_KNOWS_LONG_NAMES 0x0001
48#define SMB_FLAGS2_MASK 0xf847
49
50// Field offsets
51#define SMB_OFFSET_CMD 4
52#define SMB_OFFSET_NTSTATUS 5
53#define SMB_OFFSET_ECLASS 5
54#define SMB_OFFSET_ECODE 7
55#define SMB_OFFSET_FLAGS 9
56#define SMB_OFFSET_FLAGS2 10
57#define SMB_OFFSET_EXTRA 12
58#define SMB_OFFSET_TID 24
59#define SMB_OFFSET_PID 26
60#define SMB_OFFSET_UID 28
61#define SMB_OFFSET_MID 30
62#define SMB_OFFSET_WORDCOUNT 32
63#define SMB_OFFSET_ANDX_CMD 33
64#define SMB_OFFSET_ANDX_RESERVED 34
65#define SMB_OFFSET_ANDX_OFFSET 35
66
67// Transaction2 Request Field offsets
68#define SMB_TRANS2_REQ_OFFSET_TOTALPARAMCOUNT 33
69#define SMB_TRANS2_REQ_OFFSET_TOTALDATACOUNT 35
70#define SMB_TRANS2_REQ_OFFSET_MAXPARAMCOUNT 37
71#define SMB_TRANS2_REQ_OFFSET_MAXDATACOUNT 39
72#define SMB_TRANS2_REQ_OFFSET_MAXSETUPCOUNT 41
73#define SMB_TRANS2_REQ_OFFSET_RESERVED 42
74#define SMB_TRANS2_REQ_OFFSET_FLAGS 43
75#define SMB_TRANS2_REQ_OFFSET_TIMEOUT 45
76#define SMB_TRANS2_REQ_OFFSET_RESERVED2 49
77#define SMB_TRANS2_REQ_OFFSET_PARAMCOUNT 51
78#define SMB_TRANS2_REQ_OFFSET_PARAMOFFSET 53
79#define SMB_TRANS2_REQ_OFFSET_DATACOUNT 55
80#define SMB_TRANS2_REQ_OFFSET_DATAOFFSET 57
81#define SMB_TRANS2_REQ_OFFSET_SETUPCOUNT 59
82#define SMB_TRANS2_REQ_OFFSET_RESERVED3 60
83#define SMB_TRANS2_REQ_OFFSET_SETUP0 61
84
85// Transaction2 Response Field offsets
86#define SMB_TRANS2_RSP_OFFSET_TOTALPARAMCOUNT 33
87#define SMB_TRANS2_RSP_OFFSET_TOTALDATACOUNT 35
88#define SMB_TRANS2_RSP_OFFSET_RESERVED 37
89#define SMB_TRANS2_RSP_OFFSET_PARAMCOUNT 39
90#define SMB_TRANS2_RSP_OFFSET_PARAMOFFSET 41
91#define SMB_TRANS2_RSP_OFFSET_PARAMDISPLACEMENT 43
92#define SMB_TRANS2_RSP_OFFSET_DATACOUNT 45
93#define SMB_TRANS2_RSP_OFFSET_DATAOFFSET 47
94#define SMB_TRANS2_RSP_OFFSET_DATADISPLACEMENT 49
95#define SMB_TRANS2_RSP_OFFSET_SETUPCOUNT 51
96#define SMB_TRANS2_RSP_OFFSET_RESERVED2 52
97#define SMB_TRANS2_RSP_OFFSET_BYTECOUNT 53
98#define SMB_TRANS2_RSP_OFFSET_PAD 55
99
100// SMB File Attributes Encoding (16-bit)
101#define ATTR_READONLY 0x01
102#define ATTR_HIDDEN 0x02
103#define ATTR_SYSTEM 0x04
104#define ATTR_VOLUME 0x08
105#define ATTR_DIRECTORY 0x10
106#define ATTR_ARCHIVE 0x20
107
108// SMB Extended File Attributes Encoding (32-bit)
109#define EXT_ATTR_READONLY 0x001
110#define EXT_ATTR_HIDDEN 0x002
111#define EXT_ATTR_SYSTEM 0x004
112#define EXT_ATTR_DIRECTORY 0x010
113#define EXT_ATTR_ARCHIVE 0x020
114#define EXT_ATTR_NORMAL 0x080
115#define EXT_ATTR_TEMPORARY 0x100
116#define EXT_ATTR_COMPRESSED 0x800
117
118// SMB Information Level
119#define SMB_INFO_STANDARD 0x001
120#define SMB_INFO_QUERY_EA_SIZE 0x002
121#define SMB_INFO_QUERY_EAS_FROM_LIST 0x003
122#define SMB_QUERY_FILE_BASIC_INFO 0x101
123#define SMB_QUERY_FILE_STANDARD_INFO 0x102
124#define SMB_FIND_FILE_NAMES_INFO 0x103
125#define SMB_FIND_FILE_BOTH_DIRECTORY_INFO 0x104
126#define SMB_FIND_FILE_UNIX 0x202
127
128// SMB Search Flags
129#define CLOSE_SEARCH_AFTER_REQUEST 0x01
130#define CLOSE_SEARCH_IF_EOS 0x02
131#define RESUME_SEARCH 0x04
132#define CONTINUE_SEARCH 0x08
133#define BACKUP_INTENT_SEARCH 0x10
134
135// SMB Server Capabilities
136#define SERVER_CAP_EXTENDED_SECURITY 0x80000000
137#define SERVER_CAP_COMPRESSED_DATA 0x40000000
138#define SERVER_CAP_BULK_TRANSFER 0x20000000
139#define SERVER_CAP_UNIX 0x00800000
140#define SERVER_CAP_LARGE_WRITEX 0x00008000
141#define SERVER_CAP_LARGE_READX 0x00004000
142#define SERVER_CAP_INFOLEVEL_PASSTHROUGH 0x00002000
143#define SERVER_CAP_DFS 0x00001000
144#define SERVER_CAP_NT_FIND 0x00000200
145#define SERVER_CAP_LOCK_AND_READ 0x00000100
146#define SERVER_CAP_LEVEL_II_OPLOCKS 0x00000080
147#define SERVER_CAP_STATUS32 0x00000040
148#define SERVER_CAP_RPC_REMOTE_APIS 0x00000020
149#define SERVER_CAP_NT_SMBS 0x00000010
150#define SERVER_CAP_LARGE_FILES 0x00000008
151#define SERVER_CAP_UNICODE 0x00000004
152#define SERVER_CAP_MPX_MODE 0x00000002
153#define SERVER_CAP_RAW_MODE 0x00000001
154
155// SMB Client Capabilities
156#define CLIENT_CAP_EXTENDED_SECURITY SERVER_CAP_EXTENDED_SECURITY
157#define CLIENT_CAP_LARGE_WRITEX SERVER_CAP_LARGE_WRITEX
158#define CLIENT_CAP_LARGE_READX SERVER_CAP_LARGE_READX
159#define CLIENT_CAP_NT_FIND SERVER_CAP_NT_FIND
160#define CLIENT_CAP_LEVEL_II_OPLOCKS SERVER_CAP_LEVEL_II_OPLOCKS
161#define CLIENT_CAP_STATUS32 SERVER_CAP_STATUS32
162#define CLIENT_CAP_NT_SMBS SERVER_CAP_NT_SMBS
163#define CLIENT_CAP_LARGE_FILES SERVER_CAP_LARGE_FILES
164#define CLIENT_CAP_UNICODE SERVER_CAP_UNICODE
165
166// Security Modes
167#define NEGOTIATE_SECURITY_SIGNATURES_REQUIRED 0x08
168#define NEGOTIATE_SECURITY_SIGNATURES_ENABLED 0x04
169#define NEGOTIATE_SECURITY_CHALLENGE_RESPONSE 0x02
170#define NEGOTIATE_SECURITY_USER_LEVEL 0x01
171
172// SMB Commands
173#define SMB_COM_CREATE_DIRECTORY 0x00
174#define SMB_COM_DELETE_DIRECTORY 0x01
175#define SMB_COM_OPEN 0x02
176#define SMB_COM_CREATE 0x03
177#define SMB_COM_CLOSE 0x04
178#define SMB_COM_FLUSH 0x05
179#define SMB_COM_DELETE 0x06
180#define SMB_COM_RENAME 0x07
181#define SMB_COM_QUERY_INFORMATION 0x08
182#define SMB_COM_SET_INFORMATION 0x09
183#define SMB_COM_READ 0x0a
184#define SMB_COM_WRITE 0x0b
185#define SMB_COM_LOCK_BYTE_RANGE 0x0c
186#define SMB_COM_UNLOCK_BYTE_RANGE 0x0d
187#define SMB_COM_CREATE_TEMPORARY 0x0e
188#define SMB_COM_CREATE_NEW 0x0f
189#define SMB_COM_CHECK_DIRECTORY 0x10
190#define SMB_COM_PROCESS_EXIT 0x11
191#define SMB_COM_SEEK 0x12
192#define SMB_COM_LOCK_AND_READ 0x13
193#define SMB_COM_WRITE_AND_UNLOCK 0x14
194#define SMB_COM_READ_RAW 0x1a
195#define SMB_COM_READ_MPX 0x1b
196#define SMB_COM_READ_MPX_SECONDARY 0x1c
197#define SMB_COM_WRITE_RAW 0x1d
198#define SMB_COM_WRITE_MPX 0x1e
199#define SMB_COM_WRITE_MPX_SECONDARY 0x1f
200#define SMB_COM_WRITE_COMPLETE 0x20
201#define SMB_COM_QUERY_SERVER 0x21
202#define SMB_COM_SET_INFORMATION2 0x22
203#define SMB_COM_QUERY_INFORMATION2 0x23
204#define SMB_COM_LOCKING_ANDX 0x24
205#define SMB_COM_TRANSACTION 0x25
206#define SMB_COM_TRANSACTION_SECONDARY 0x26
207#define SMB_COM_IOCTL 0x27
208#define SMB_COM_IOCTL_SECONDARY 0x28
209#define SMB_COM_COPY 0x29
210#define SMB_COM_MOVE 0x2a
211#define SMB_COM_ECHO 0x2b
212#define SMB_COM_WRITE_AND_CLOSE 0x2c
213#define SMB_COM_OPEN_ANDX 0x2d
214#define SMB_COM_READ_ANDX 0x2e
215#define SMB_COM_WRITE_ANDX 0x2f
216#define SMB_COM_NEW_FILE_SIZE 0x30
217#define SMB_COM_CLOSE_AND_TREE_DISC 0x31
218#define SMB_COM_TRANSACTION2 0x32
219#define SMB_COM_TRANSACTION2_SECONDARY 0x33
220#define SMB_COM_FIND_CLOSE2 0x34
221#define SMB_COM_FIND_NOTIFY_CLOSE 0x35
222#define SMB_COM_TREE_CONNECT 0x70
223#define SMB_COM_TREE_DISCONNECT 0x71
224#define SMB_COM_NEGOTIATE 0x72
225#define SMB_COM_SESSION_SETUP_ANDX 0x73
226#define SMB_COM_LOGOFF_ANDX 0x74
227#define SMB_COM_TREE_CONNECT_ANDX 0x75
228#define SMB_COM_QUERY_INFORMATION_DISK 0x80
229#define SMB_COM_SEARCH 0x81
230#define SMB_COM_FIND 0x82
231#define SMB_COM_FIND_UNIQUE 0x83
232#define SMB_COM_FIND_CLOSE 0x84
233#define SMB_COM_NT_TRANSACT 0xa0
234#define SMB_COM_NT_TRANSACT_SECONDARY 0xa1
235#define SMB_COM_NT_CREATE_ANDX 0xa2
236#define SMB_COM_NT_CANCEL 0xa4
237#define SMB_COM_NT_RENAME 0xa5
238#define SMB_COM_OPEN_PRINT_FILE 0xc0
239#define SMB_COM_WRITE_PRINT_FILE 0xc1
240#define SMB_COM_CLOSE_PRINT_FILE 0xc2
241#define SMB_COM_GET_PRINT_QUEUE 0xc3
242#define SMB_COM_READ_BULK 0xd8
243#define SMB_COM_WRITE_BULK 0xd9
244#define SMB_COM_WRITE_BULK_DATA 0xda
245#define SMB_COM_NONE 0xff
246
247// Setup[0] Transaction2 Subcommands
248#define TRANS2_OPEN2 0x00
249#define TRANS2_FIND_FIRST2 0x01
250#define TRANS2_FIND_NEXT2 0x02
251#define TRANS2_QUERY_FS_INFORMATION 0x03
252#define TRANS2_SET_FS_INFORMATION 0x04
253#define TRANS2_QUERY_PATH_INFORMATION 0X05
254#define TRANS2_SET_PATH_INFORMATION 0x06
255#define TRANS2_QUERY_FILE_INFORMATION 0x07
256#define TRANS2_SET_FILE_INFORMATION 0x08
257#define TRANS2_FSCTL 0x09
258#define TRANS2_IOCTL2 0x0a
259#define TRANS2_FIND_NOTIFY_FIRST 0x0b
260#define TRANS2_FIND_NOTIFY_NEXT 0x0c
261#define TRANS2_CREATE_DIRECTORY 0x0d
262#define TRANS2_SESSION_SETUP 0x0e
263#define TRANS2_GET_DFS_REFERRAL 0x10
264#define TRANS2_REPORT_DFS_INCONSISTENCY 0x11
265
266// DOS Error Class
267#define DOS_ECLASS_SUCCESS 0x00
268
269// NT Status
270#define STATUS_SUCCESS 0x00000000
271#define STATUS_NO_MEDIA_IN_DEVICE 0xc0000013
272#define STATUS_ACCESS_DENIED 0xc0000022
273#define STATUS_OBJECT_NAME_NOT_FOUND 0xc0000034
274#define STATUS_LOGON_FAILURE 0xc000006d
275
276typedef struct
277{
278 char ServerIP[16];
279 u32 MaxBufferSize;
280 u32 SessionKey;
281 u32 Capabilities;
282 u16 MaxMpxCount;
283 u8 SecurityMode; // 0 = share level, 1 = user level
284 u8 PasswordType; // 0 = PlainText passwords, 1 = use challenge/response
285 char PrimaryDomainServerName[64];
286 u8 EncryptionKey[8];
288
289#define SERVER_SHARE_SECURITY_LEVEL 0
290#define SERVER_USER_SECURITY_LEVEL 1
291#define SERVER_USE_PLAINTEXT_PASSWORD 0
292#define SERVER_USE_ENCRYPTED_PASSWORD 1
293
294typedef struct
295{
296 s64 Created;
297 s64 LastAccess;
298 s64 LastWrite;
299 s64 Change;
300 u32 FileAttributes;
301 u64 AllocationSize;
302 u64 EndOfFile;
303 u32 LinkCount;
304 u8 DeletePending;
305 u8 IsDirectory;
307
308typedef struct
309{
310 int SID;
311 int EOS;
312 PathInformation_t fileInfo;
313 char FileName[];
315
316typedef struct
317{
318 u32 Magic;
319 u8 Cmd;
320 short Eclass;
321 short Ecode;
322 u8 Flags;
323 u16 Flags2;
324 u8 Extra[12];
325 u16 TID;
326 u16 PID;
327 u16 UID;
328 u16 MID;
329} __attribute__((packed)) SMBHeader_t;
330
331typedef struct
332{
333 u16 TotalParamCount;
334 u16 TotalDataCount;
335 u16 MaxParamCount;
336 u16 MaxDataCount;
337 u8 MaxSetupCount;
338 u8 Reserved;
339 u16 Flags;
340 u32 Timeout;
341 u16 Reserved2;
342 u16 ParamCount;
343 u16 ParamOffset;
344 u16 DataCount;
345 u16 DataOffset;
346 u8 SetupCount;
347 u8 Reserved3;
348} __attribute__((packed)) SMBTransactionRequest_t;
349
350typedef struct
351{
352 u16 TotalParamCount;
353 u16 TotalDataCount;
354 u16 Reserved;
355 u16 ParamCount;
356 u16 ParamOffset;
357 u16 ParamDisplacement;
358 u16 DataCount;
359 u16 DataOffset;
360 u16 DataDisplacement;
361 u8 SetupCount;
362 u8 Reserved2;
363} __attribute__((packed)) SMBTransactionResponse_t;
364
365typedef struct
366{
367 SMBHeader_t smbH;
368 u8 smbWordcount;
369 u16 ByteCount;
370 u8 DialectFormat;
371 char DialectName[];
372} __attribute__((packed)) NegotiateProtocolRequest_t;
373
374typedef struct
375{
376 SMBHeader_t smbH;
377 u8 smbWordcount;
378 u16 DialectIndex;
379 u8 SecurityMode;
380 u16 MaxMpxCount;
381 u16 MaxVC;
382 u32 MaxBufferSize;
383 u32 MaxRawBuffer;
384 u32 SessionKey;
385 u32 Capabilities;
386 s64 SystemTime;
387 u16 ServerTimeZone;
388 u8 KeyLength;
389 u16 ByteCount;
390 u8 ByteField[];
391} __attribute__((packed)) NegotiateProtocolResponse_t;
392
393typedef struct
394{
395 SMBHeader_t smbH;
396 u8 smbWordcount;
397 u8 smbAndxCmd;
398 u8 smbAndxReserved;
399 u16 smbAndxOffset;
400 u16 MaxBufferSize;
401 u16 MaxMpxCount;
402 u16 VCNumber;
403 u32 SessionKey;
404 u16 AnsiPasswordLength;
405 u16 UnicodePasswordLength;
406 u32 reserved;
407 u32 Capabilities;
408 u16 ByteCount;
409 u8 ByteField[];
410} __attribute__((packed)) SessionSetupAndXRequest_t;
411
412typedef struct
413{
414 SMBHeader_t smbH;
415 u8 smbWordcount;
416 u8 smbAndxCmd;
417 u8 smbAndxReserved;
418 u16 smbAndxOffset;
419 u16 Action;
420 u16 ByteCount;
421} __attribute__((packed)) SessionSetupAndXResponse_t;
422
423typedef struct
424{
425 SMBHeader_t smbH;
426 u8 smbWordcount;
427 u8 smbAndxCmd;
428 u8 smbAndxReserved;
429 u16 smbAndxOffset;
430 u16 Flags;
431 u16 PasswordLength;
432 u16 ByteCount;
433 u8 ByteField[];
434} __attribute__((packed)) TreeConnectAndXRequest_t;
435
436typedef struct
437{
438 SMBHeader_t smbH;
439 u8 smbWordcount;
440 u8 smbAndxCmd;
441 u8 smbAndxReserved;
442 u16 smbAndxOffset;
443 u16 OptionalSupport;
444 u16 ByteCount;
445} __attribute__((packed)) TreeConnectAndXResponse_t;
446
447typedef struct
448{
449 SMBHeader_t smbH;
450 u8 smbWordcount;
451 u16 ByteCount;
452} __attribute__((packed)) TreeDisconnectRequest_t;
453
454typedef struct
455{
456 SMBHeader_t smbH;
457 u8 smbWordcount;
458 u16 ByteCount;
459} __attribute__((packed)) TreeDisconnectResponse_t;
460
461typedef struct
462{
463 SMBHeader_t smbH;
464 u8 smbWordcount;
465 SMBTransactionRequest_t smbTrans;
466 u16 ByteCount;
467 u8 ByteField[];
468} __attribute__((packed)) NetShareEnumRequest_t;
469
470typedef struct
471{
472 SMBHeader_t smbH;
473 u8 smbWordcount;
474 SMBTransactionResponse_t smbTrans;
475 u16 ByteCount;
476 u8 ByteField[];
477} __attribute__((packed)) NetShareEnumResponse_t;
478
479typedef struct
480{
481 SMBHeader_t smbH;
482 u8 smbWordcount;
483 u8 smbAndxCmd;
484 u8 smbAndxReserved;
485 u16 smbAndxOffset;
486 u16 ByteCount;
487} __attribute__((packed)) LogOffAndXRequest_t;
488
489typedef struct
490{
491 SMBHeader_t smbH;
492 u8 smbWordcount;
493 u8 smbAndxCmd;
494 u8 smbAndxReserved;
495 u16 smbAndxOffset;
496 u16 ByteCount;
497} __attribute__((packed)) LogOffAndXResponse_t;
498
499typedef struct
500{
501 SMBHeader_t smbH;
502 u8 smbWordcount;
503 u16 EchoCount;
504 u16 ByteCount;
505 u8 ByteField[];
506} __attribute__((packed)) EchoRequest_t;
507
508typedef struct
509{
510 SMBHeader_t smbH;
511 u8 smbWordcount;
512 u16 SequenceNumber;
513 u16 ByteCount;
514 u8 ByteField[];
515} __attribute__((packed)) EchoResponse_t;
516
517typedef struct
518{
519 SMBHeader_t smbH;
520 u8 smbWordcount;
521 u16 ByteCount;
522 u8 ByteField[];
523} __attribute__((packed)) QueryInformationDiskRequest_t;
524
525typedef struct
526{
527 SMBHeader_t smbH;
528 u8 smbWordcount;
529 u16 TotalUnits;
530 u16 BlocksPerUnit;
531 u16 BlockSize;
532 u16 FreeUnits;
533 u16 Reserved;
534 u16 ByteCount;
535} __attribute__((packed)) QueryInformationDiskResponse_t;
536
537typedef struct
538{
539 u16 LevelOfInterest;
540 u32 Reserved;
541 char FileName[];
542} __attribute__((packed)) QueryPathInformationRequestParam_t;
543
544typedef struct
545{
546 SMBHeader_t smbH;
547 u8 smbWordcount;
548 SMBTransactionRequest_t smbTrans;
549 u16 SubCommand;
550 u16 ByteCount;
551 u8 ByteField[];
552} __attribute__((packed)) QueryPathInformationRequest_t;
553
554typedef struct
555{
556 SMBHeader_t smbH;
557 u8 smbWordcount;
558 SMBTransactionResponse_t smbTrans;
559 u16 ByteCount;
560 u8 ByteField[];
561} __attribute__((packed)) QueryPathInformationResponse_t;
562
563typedef struct
564{
565 s64 Created;
566 s64 LastAccess;
567 s64 LastWrite;
568 s64 Change;
569 u32 FileAttributes;
570} __attribute__((packed)) BasicFileInfo_t;
571
572typedef struct
573{
574 u64 AllocationSize;
575 u64 EndOfFile;
576 u32 LinkCount;
577 u8 DeletePending;
578 u8 IsDirectory;
579} __attribute__((packed)) StandardFileInfo_t;
580
581typedef struct
582{
583 u16 SearchAttributes;
584 u16 SearchCount;
585 u16 Flags;
586 u16 LevelOfInterest;
587 u32 StorageType;
588 char SearchPattern[];
589} __attribute__((packed)) FindFirst2RequestParam_t;
590
591typedef struct
592{
593 u16 SearchID;
594 u16 SearchCount;
595 u16 LevelOfInterest;
596 u32 ResumeKey;
597 u16 Flags;
598 char SearchPattern[];
599} __attribute__((packed)) FindNext2RequestParam_t;
600
601typedef struct
602{
603 SMBHeader_t smbH;
604 u8 smbWordcount;
605 SMBTransactionRequest_t smbTrans;
606 u16 SubCommand;
607 u16 ByteCount;
608 u8 ByteField[];
609} __attribute__((packed)) FindFirstNext2Request_t;
610
611typedef struct
612{
613 u16 SearchID;
614 u16 SearchCount;
615 u16 EndOfSearch;
616 u16 EAErrorOffset;
617 u16 LastNameOffset;
618} __attribute__((packed)) FindFirstNext2ResponseParam_t;
619
620typedef struct
621{
622 u32 NextEntryOffset;
623 u32 FileIndex;
624 s64 Created;
625 s64 LastAccess;
626 s64 LastWrite;
627 s64 Change;
628 u64 EndOfFile;
629 u64 AllocationSize;
630 u32 FileAttributes;
631 u32 FileNameLen;
632 u32 EAListLength;
633 u16 ShortFileNameLen;
634 u8 ShortFileName[24];
635 char FileName[];
636} __attribute__((packed)) FindFirst2ResponseData_t;
637
638typedef struct
639{
640 SMBHeader_t smbH;
641 u8 smbWordcount;
642 SMBTransactionResponse_t smbTrans;
643 u16 ByteCount;
644 u8 ByteField[];
645} __attribute__((packed)) FindFirstNext2Response_t;
646
647typedef struct
648{
649 SMBHeader_t smbH;
650 u8 smbWordcount;
651 u8 smbAndxCmd;
652 u8 smbAndxReserved;
653 u16 smbAndxOffset;
654 u8 reserved;
655 short NameLength;
656 u32 Flags;
657 u32 RootDirectoryFid;
658 u32 AccessMask;
659 u64 AllocationSize;
660 u32 FileAttributes;
661 u32 ShareAccess;
662 u32 CreateDisposition;
663 u32 CreateOptions;
664 u32 ImpersonationLevel;
665 u8 SecurityFlags;
666 u16 ByteCount;
667 char ByteField[];
668} __attribute__((packed)) NTCreateAndXRequest_t;
669
670typedef struct
671{
672 SMBHeader_t smbH;
673 u8 smbWordcount;
674 u8 smbAndxCmd;
675 u8 smbAndxReserved;
676 u16 smbAndxOffset;
677 u8 OplockLevel;
678 u16 FID;
679 u32 Action;
680 s64 Created;
681 s64 LastAccess;
682 s64 LastWrite;
683 s64 Changed;
684 u32 FileAttributes;
685 u64 AllocationSize;
686 u64 FileSize;
687 u16 FileType;
688 u16 IPCState;
689 u8 IsDirectory;
690 u16 ByteCount;
691} __attribute__((packed)) NTCreateAndXResponse_t;
692
693typedef struct
694{
695 SMBHeader_t smbH;
696 u8 smbWordcount;
697 u8 smbAndxCmd;
698 u8 smbAndxReserved;
699 u16 smbAndxOffset;
700 u16 Flags;
701 u16 AccessMask;
702 u16 SearchAttributes;
703 u16 FileAttributes;
704 u8 Created[4];
705 u16 CreateOptions;
706 u32 AllocationSize;
707 u32 reserved[2];
708 u16 ByteCount;
709 u8 ByteField[];
710} __attribute__((packed)) OpenAndXRequest_t;
711
712typedef struct
713{
714 SMBHeader_t smbH;
715 u8 smbWordcount;
716 u8 smbAndxCmd;
717 u8 smbAndxReserved;
718 u16 smbAndxOffset;
719 u16 FID;
720 u16 FileAttributes;
721 u8 LastWrite[4];
722 u32 FileSize;
723 u16 GrantedAccess;
724 u16 FileType;
725 u16 IPCState;
726 u16 Action;
727 u32 ServerFID;
728 u16 reserved;
729 u16 ByteCount;
730} __attribute__((packed)) OpenAndXResponse_t;
731
732typedef struct
733{
734 SMBHeader_t smbH;
735 u8 smbWordcount;
736 u8 smbAndxCmd;
737 u8 smbAndxReserved;
738 u16 smbAndxOffset;
739 u16 FID;
740 u32 OffsetLow;
741 u16 MaxCountLow;
742 u16 MinCount;
743 union
744 {
745 u32 Timeout;
746 u16 MaxCountHigh;
747 };
748 u16 Remaining;
749 u32 OffsetHigh;
750 u16 ByteCount;
751} __attribute__((packed)) ReadAndXRequest_t;
752
753typedef struct
754{
755 SMBHeader_t smbH;
756 u8 smbWordcount;
757 u8 smbAndxCmd;
758 u8 smbAndxReserved;
759 u16 smbAndxOffset;
760 u16 Remaining;
761 u16 DataCompactionMode;
762 u16 reserved;
763 u16 DataLengthLow;
764 u16 DataOffset;
765 u32 DataLengthHigh;
766 u8 reserved2[6];
767 u16 ByteCount;
768} __attribute__((packed)) ReadAndXResponse_t;
769
770typedef struct
771{
772 SMBHeader_t smbH;
773 u8 smbWordcount;
774 u8 smbAndxCmd;
775 u8 smbAndxReserved;
776 u16 smbAndxOffset;
777 u16 FID;
778 u32 OffsetLow;
779 u32 Reserved;
780 u16 WriteMode;
781 u16 Remaining;
782 u16 DataLengthHigh;
783 u16 DataLengthLow;
784 u16 DataOffset;
785 u32 OffsetHigh;
786 u16 ByteCount;
787} __attribute__((packed)) WriteAndXRequest_t;
788
789typedef struct
790{
791 SMBHeader_t smbH;
792 u8 smbWordcount;
793 u8 smbAndxCmd;
794 u8 smbAndxReserved;
795 u16 smbAndxOffset;
796 u16 Count;
797 u16 Remaining;
798 u16 CountHigh;
799 u16 Reserved;
800} __attribute__((packed)) WriteAndXResponse_t;
801
802typedef struct
803{
804 SMBHeader_t smbH;
805 u8 smbWordcount;
806 u16 FID;
807 u32 LastWrite;
808 u16 ByteCount;
809} __attribute__((packed)) CloseRequest_t;
810
811typedef struct
812{
813 SMBHeader_t smbH;
814 u8 smbWordcount;
815 u16 ByteCount;
816} __attribute__((packed)) CloseResponse_t;
817
818typedef struct
819{
820 SMBHeader_t smbH;
821 u8 smbWordcount;
822 u16 SearchAttributes;
823 u16 ByteCount;
824 u8 BufferFormat;
825 char FileName[];
826} __attribute__((packed)) DeleteRequest_t;
827
828typedef struct
829{
830 SMBHeader_t smbH;
831 u8 smbWordcount;
832 u16 ByteCount;
833} __attribute__((packed)) DeleteResponse_t;
834
835typedef struct
836{
837 SMBHeader_t smbH;
838 u8 smbWordcount;
839 u16 ByteCount;
840 u8 BufferFormat;
841 char DirectoryName[];
842} __attribute__((packed)) ManageDirectoryRequest_t;
843
844typedef struct
845{
846 SMBHeader_t smbH;
847 u8 smbWordcount;
848 u16 ByteCount;
849} __attribute__((packed)) ManageDirectoryResponse_t;
850
851typedef struct
852{
853 SMBHeader_t smbH;
854 u8 smbWordcount;
855 u16 SearchAttributes;
856 u16 ByteCount;
857 u8 ByteField[];
858} __attribute__((packed)) RenameRequest_t;
859
860typedef struct
861{
862 SMBHeader_t smbH;
863 u8 smbWordcount;
864 u16 ByteCount;
865} __attribute__((packed)) RenameResponse_t;
866
867// function prototypes
868extern server_specs_t *getServerSpecs(void);
869
870extern int smb_Connect(char *SMBServerIP, int SMBServerPort);
871extern int smb_Disconnect(void);
872
873extern int smb_NegotiateProtocol(u32 *capabilities);
874extern int smb_SessionSetupAndX(char *User, char *Password, int PasswordType, u32 capabilities);
875extern int smb_TreeConnectAndX(int UID, char *ShareName, char *Password, int PasswordType);
876extern int smb_TreeDisconnect(int UID, int TID);
877extern int smb_NetShareEnum(int UID, int TID, ShareEntry_t *shareEntries, int index, int maxEntries);
878extern int smb_QueryInformationDisk(int UID, int TID, smbQueryDiskInfo_out_t *QueryInformationDisk);
879extern int smb_QueryPathInformation(int UID, int TID, PathInformation_t *Info, char *Path);
880extern int smb_FindFirstNext2(int UID, int TID, char *Path, int cmd, SearchInfo_t *info);
881extern int smb_LogOffAndX(int UID);
882extern int smb_Echo(void *echo, int len);
883
884extern int smb_OpenAndX(int UID, int TID, char *filename, s64 *filesize, int mode);
885extern int smb_ReadAndX(int UID, int TID, int FID, s64 offset, void *readbuf, int nbytes);
886extern int smb_WriteAndX(int UID, int TID, int FID, s64 offset, void *writebuf, int nbytes);
887extern int smb_ReadFile(int UID, int TID, int FID, s64 fileoffset, void *readbuf, int nbytes);
888extern int smb_WriteFile(int UID, int TID, int FID, s64 fileoffset, void *writebuf, int nbytes);
889extern int smb_Close(int UID, int TID, int FID);
890extern int smb_Delete(int UID, int TID, char *Path);
891extern int smb_ManageDirectory(int UID, int TID, char *Path, int cmd);
892extern int smb_Rename(int UID, int TID, char *oldPath, char *newPath);
893
894#define MAX_SMB_BUF 4096 // must fit on u16 !!!
895#define MAX_SMB_BUF_HDR 128 // Must be at least as large as the largest header structure.
896
897#endif