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