smb.h revision 56893
1/*
2   Copyright (C) Andrew Tridgell 1995-1999
3
4   This software may be distributed either under the terms of the
5   BSD-style license that accompanies tcpdump or the GNU GPL version 2
6   or later */
7
8#define CVAL(buf,pos) (((unsigned char *)(buf))[pos])
9#define PVAL(buf,pos) ((unsigned)CVAL(buf,pos))
10#define SCVAL(buf,pos,val) (CVAL(buf,pos) = (val))
11
12#define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8)
13#define IVAL(buf,pos) (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16)
14#define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8)
15#define SIVALX(buf,pos,val) (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16))
16#define SVALS(buf,pos) ((int16)SVAL(buf,pos))
17#define IVALS(buf,pos) ((int32)IVAL(buf,pos))
18#define SSVAL(buf,pos,val) SSVALX((buf),(pos),((uint16)(val)))
19#define SIVAL(buf,pos,val) SIVALX((buf),(pos),((uint32)(val)))
20#define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16)(val)))
21#define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32)(val)))
22
23/* now the reverse routines - these are used in nmb packets (mostly) */
24#define SREV(x) ((((x)&0xFF)<<8) | (((x)>>8)&0xFF))
25#define IREV(x) ((SREV(x)<<16) | (SREV((x)>>16)))
26
27#define RSVAL(buf,pos) SREV(SVAL(buf,pos))
28#define RIVAL(buf,pos) IREV(IVAL(buf,pos))
29#define RSSVAL(buf,pos,val) SSVAL(buf,pos,SREV(val))
30#define RSIVAL(buf,pos,val) SIVAL(buf,pos,IREV(val))
31
32#define uint16 unsigned short
33#define uint32 unsigned int
34#ifndef uchar
35#define uchar unsigned char
36#endif
37
38#ifndef MIN
39#define MIN(a,b) ((a)<(b)?(a):(b))
40#endif
41
42/* the complete */
43#define SMBmkdir      0x00   /* create directory */
44#define SMBrmdir      0x01   /* delete directory */
45#define SMBopen       0x02   /* open file */
46#define SMBcreate     0x03   /* create file */
47#define SMBclose      0x04   /* close file */
48#define SMBflush      0x05   /* flush file */
49#define SMBunlink     0x06   /* delete file */
50#define SMBmv         0x07   /* rename file */
51#define SMBgetatr     0x08   /* get file attributes */
52#define SMBsetatr     0x09   /* set file attributes */
53#define SMBread       0x0A   /* read from file */
54#define SMBwrite      0x0B   /* write to file */
55#define SMBlock       0x0C   /* lock byte range */
56#define SMBunlock     0x0D   /* unlock byte range */
57#define SMBctemp      0x0E   /* create temporary file */
58#define SMBmknew      0x0F   /* make new file */
59#define SMBchkpth     0x10   /* check directory path */
60#define SMBexit       0x11   /* process exit */
61#define SMBlseek      0x12   /* seek */
62#define SMBtcon       0x70   /* tree connect */
63#define SMBtconX      0x75   /* tree connect and X*/
64#define SMBtdis       0x71   /* tree disconnect */
65#define SMBnegprot    0x72   /* negotiate protocol */
66#define SMBdskattr    0x80   /* get disk attributes */
67#define SMBsearch     0x81   /* search directory */
68#define SMBsplopen    0xC0   /* open print spool file */
69#define SMBsplwr      0xC1   /* write to print spool file */
70#define SMBsplclose   0xC2   /* close print spool file */
71#define SMBsplretq    0xC3   /* return print queue */
72#define SMBsends      0xD0   /* send single block message */
73#define SMBsendb      0xD1   /* send broadcast message */
74#define SMBfwdname    0xD2   /* forward user name */
75#define SMBcancelf    0xD3   /* cancel forward */
76#define SMBgetmac     0xD4   /* get machine name */
77#define SMBsendstrt   0xD5   /* send start of multi-block message */
78#define SMBsendend    0xD6   /* send end of multi-block message */
79#define SMBsendtxt    0xD7   /* send text of multi-block message */
80
81/* Core+ protocol */
82#define SMBlockread	  0x13   /* Lock a range and read */
83#define SMBwriteunlock 0x14 /* Unlock a range then write */
84#define SMBreadbraw   0x1a  /* read a block of data with no smb header */
85#define SMBwritebraw  0x1d  /* write a block of data with no smb header */
86#define SMBwritec     0x20  /* secondary write request */
87#define SMBwriteclose 0x2c  /* write a file then close it */
88
89/* dos extended protocol */
90#define SMBreadBraw      0x1A   /* read block raw */
91#define SMBreadBmpx      0x1B   /* read block multiplexed */
92#define SMBreadBs        0x1C   /* read block (secondary response) */
93#define SMBwriteBraw     0x1D   /* write block raw */
94#define SMBwriteBmpx     0x1E   /* write block multiplexed */
95#define SMBwriteBs       0x1F   /* write block (secondary request) */
96#define SMBwriteC        0x20   /* write complete response */
97#define SMBsetattrE      0x22   /* set file attributes expanded */
98#define SMBgetattrE      0x23   /* get file attributes expanded */
99#define SMBlockingX      0x24   /* lock/unlock byte ranges and X */
100#define SMBtrans         0x25   /* transaction - name, bytes in/out */
101#define SMBtranss        0x26   /* transaction (secondary request/response) */
102#define SMBioctl         0x27   /* IOCTL */
103#define SMBioctls        0x28   /* IOCTL  (secondary request/response) */
104#define SMBcopy          0x29   /* copy */
105#define SMBmove          0x2A   /* move */
106#define SMBecho          0x2B   /* echo */
107#define SMBopenX         0x2D   /* open and X */
108#define SMBreadX         0x2E   /* read and X */
109#define SMBwriteX        0x2F   /* write and X */
110#define SMBsesssetupX    0x73   /* Session Set Up & X (including User Logon) */
111#define SMBffirst        0x82   /* find first */
112#define SMBfunique       0x83   /* find unique */
113#define SMBfclose        0x84   /* find close */
114#define SMBinvalid       0xFE   /* invalid command */
115
116/* Extended 2.0 protocol */
117#define SMBtrans2        0x32   /* TRANS2 protocol set */
118#define SMBtranss2       0x33   /* TRANS2 protocol set, secondary command */
119#define SMBfindclose     0x34   /* Terminate a TRANSACT2_FINDFIRST */
120#define SMBfindnclose    0x35   /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
121#define SMBulogoffX      0x74   /* user logoff */
122
123/* NT SMB extensions. */
124#define SMBnttrans       0xA0   /* NT transact */
125#define SMBnttranss      0xA1   /* NT transact secondary */
126#define SMBntcreateX     0xA2   /* NT create and X */
127#define SMBntcancel      0xA4   /* NT cancel */
128
129/* pathworks special */
130#define pSETDIR '\377'
131
132
133/* these are the TRANS2 sub commands */
134#define TRANSACT2_OPEN          0
135#define TRANSACT2_FINDFIRST     1
136#define TRANSACT2_FINDNEXT      2
137#define TRANSACT2_QFSINFO       3
138#define TRANSACT2_SETFSINFO     4
139#define TRANSACT2_QPATHINFO     5
140#define TRANSACT2_SETPATHINFO   6
141#define TRANSACT2_QFILEINFO     7
142#define TRANSACT2_SETFILEINFO   8
143#define TRANSACT2_FSCTL         9
144#define TRANSACT2_IOCTL           10
145#define TRANSACT2_FINDNOTIFYFIRST 11
146#define TRANSACT2_FINDNOTIFYNEXT  12
147#define TRANSACT2_MKDIR           13
148
149#define PTR_DIFF(p1,p2) ((unsigned long)(((char *)(p1)) - (char *)(p2)))
150
151/* some protos */
152const uchar *fdata(const uchar *buf, const char *fmt, const uchar *maxbuf);
153