KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > smb > PacketType


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.smb;
18
19 /**
20  * SMB packet type class
21  */

22 public class PacketType
23 {
24     // SMB packet types
25

26     public static final int CreateDirectory = 0x00;
27     public static final int DeleteDirectory = 0x01;
28     public static final int OpenFile = 0x02;
29     public static final int CreateFile = 0x03;
30     public static final int CloseFile = 0x04;
31     public static final int FlushFile = 0x05;
32     public static final int DeleteFile = 0x06;
33     public static final int RenameFile = 0x07;
34     public static final int GetFileAttributes = 0x08;
35     public static final int SetFileAttributes = 0x09;
36     public static final int ReadFile = 0x0A;
37     public static final int WriteFile = 0x0B;
38     public static final int LockFile = 0x0C;
39     public static final int UnLockFile = 0x0D;
40     public static final int CreateTemporary = 0x0E;
41     public static final int CreateNew = 0x0F;
42     public static final int CheckDirectory = 0x10;
43
44     public static final int ProcessExit = 0x11;
45     public static final int SeekFile = 0x12;
46     public static final int LockAndRead = 0x13;
47     public static final int WriteAndUnlock = 0x14;
48     public static final int ReadRaw = 0x1A;
49     public static final int ReadMpx = 0x1B;
50     public static final int ReadMpxSecondary = 0x1C;
51     public static final int WriteRaw = 0x1D;
52     public static final int WriteMpx = 0x1E;
53     public static final int WriteComplete = 0x20;
54     public static final int SetInformation2 = 0x22;
55     public static final int QueryInformation2 = 0x23;
56     public static final int LockingAndX = 0x24;
57     public static final int Transaction = 0x25;
58     public static final int TransactionSecond = 0x26;
59     public static final int IOCtl = 0x27;
60     public static final int IOCtlSecondary = 0x28;
61     public static final int Copy = 0x29;
62     public static final int Move = 0x2A;
63     public static final int Echo = 0x2B;
64     public static final int WriteAndClose = 0x2C;
65     public static final int OpenAndX = 0x2D;
66     public static final int ReadAndX = 0x2E;
67     public static final int WriteAndX = 0x2F;
68     public static final int CloseAndTreeDisc = 0x31;
69     public static final int Transaction2 = 0x32;
70     public static final int Transaction2Second= 0x33;
71     public static final int FindClose2 = 0x34;
72     public static final int FindNotifyClose = 0x35;
73
74     public static final int TreeConnect = 0x70;
75     public static final int TreeDisconnect = 0x71;
76     public static final int Negotiate = 0x72;
77     public static final int SessionSetupAndX = 0x73;
78     public static final int LogoffAndX = 0x74;
79     public static final int TreeConnectAndX = 0x75;
80   
81     public static final int DiskInformation = 0x80;
82     public static final int Search = 0x81;
83     public static final int Find = 0x82;
84     public static final int FindUnique = 0x83;
85
86     public static final int NTTransact = 0xA0;
87     public static final int NTTransactSecond = 0xA1;
88     public static final int NTCreateAndX = 0xA2;
89     public static final int NTCancel = 0xA4;
90
91     public static final int OpenPrintFile = 0xC0;
92     public static final int WritePrintFile = 0xC1;
93     public static final int ClosePrintFile = 0xC2;
94     public static final int GetPrintQueue = 0xC3;
95
96     // Send message codes
97

98     public static final int SendMessage = 0xD0;
99     public static final int SendBroadcast = 0xD1;
100     public static final int SendForward = 0xD2;
101     public static final int CancelForward = 0xD3;
102     public static final int GetMachineName = 0xD4;
103     public static final int SendMultiStart = 0xD5;
104     public static final int SendMultiEnd = 0xD6;
105     public static final int SendMultiText = 0xD7;
106
107     // Transaction2 operation codes
108

109     public static final int Trans2Open = 0x00;
110     public static final int Trans2FindFirst = 0x01;
111     public static final int Trans2FindNext = 0x02;
112     public static final int Trans2QueryFileSys= 0x03;
113     public static final int Trans2QueryPath = 0x05;
114     public static final int Trans2SetPath = 0x06;
115     public static final int Trans2QueryFile = 0x07;
116     public static final int Trans2SetFile = 0x08;
117     public static final int Trans2CreateDir = 0x0D;
118     public static final int Trans2SessSetup = 0x0E;
119
120     // Remote admin protocol (RAP) codes
121

122     public static final int RAPShareEnum = 0;
123     public static final int RAPShareGetInfo = 1;
124     public static final int RAPSessionEnum = 6;
125     public static final int RAPServerGetInfo = 13;
126     public static final int NetServerDiskEnum = 15;
127     public static final int NetGroupEnum = 47;
128     public static final int RAPUserGetInfo = 56;
129     public static final int RAPWkstaGetInfo = 63;
130     public static final int RAPServerEnum = 94;
131     public static final int RAPServerEnum2 = 104;
132     public static final int RAPWkstaUserLogon = 132;
133     public static final int RAPWkstaUserLogoff= 133;
134     public static final int RAPChangePassword = 214;
135
136     // Service information/control codes
137

138     public static final int NetServiceEnum = 39;
139     public static final int NetServiceInstall = 40;
140     public static final int NetServiceControl = 41;
141
142     // User/group information codes
143

144     public static final int NetGroupGetUsers = 52;
145     public static final int NetUserEnum = 53;
146     public static final int NetUserGetGroups = 59;
147
148     // Printer/print queue admin codes
149

150     public static final int NetPrintQEnum = 69;
151     public static final int NetPrintQGetInfo = 70;
152     public static final int NetPrintQSetInfo = 71;
153     public static final int NetPrintQAdd = 72;
154     public static final int NetPrintQDel = 73;
155     public static final int NetPrintQPause = 74;
156     public static final int NetPrintQContinue = 75;
157     public static final int NetPrintJobEnum = 76;
158     public static final int NetPrintJobGetInfo= 77;
159     public static final int NetPrintJobSetInfo= 78;
160     public static final int NetPrintJobDelete = 81;
161     public static final int NetPrintJobPause = 82;
162     public static final int NetPrintJobContinue = 83;
163     public static final int NetPrintDestEnum = 84;
164     public static final int NetPrintDestGetInfo = 85;
165     public static final int NetPrintDestControl = 86;
166
167     // Transaction named pipe sub-commands
168

169     public static final int CallNamedPipe = 0x54;
170     public static final int WaitNamedPipe = 0x53;
171     public static final int PeekNmPipe = 0x23;
172     public static final int QNmPHandState = 0x21;
173     public static final int SetNmPHandState = 0x01;
174     public static final int QNmPipeInfo = 0x22;
175     public static final int TransactNmPipe = 0x26;
176     public static final int RawReadNmPipe = 0x11;
177     public static final int RawWriteNmPipe = 0x31;
178
179     // Miscellaneous codes
180

181     public static final int NetBIOSEnum = 92;
182   
183     // NT transaction function codes
184

185     public static final int NTTransCreate = 1;
186     public static final int NTTransIOCtl = 2;
187     public static final int NTTransSetSecurityDesc = 3;
188     public static final int NTTransNotifyChange = 4;
189     public static final int NTTransRename = 5;
190     public static final int NTTransQuerySecurityDesc = 6;
191     public static final int NTTransGetUserQuota = 7;
192     public static final int NTTransSetUserQuota = 8;
193   
194     // Flag to indicate no chained AndX command
195

196     public static final int NoChainedCommand = 0xFF;
197
198     // SMB command names (block 1)
199

200     private static String JavaDoc[] _cmdNames1 = { "CreateDirectory",
201                                                                              "DeleteDirectory",
202                                                                              "OpenFile",
203                                                                              "CreateFile",
204                                                                              "CloseFile",
205                                                                              "FlushFile",
206                                                                              "DeleteFile",
207                                                                              "RenameFile",
208                                                                              "GetFileAttributes",
209                                                                              "SetFileAttributes",
210                                                                              "ReadFile",
211                                                                              "WriteFile",
212                                                                              "LockFile",
213                                                                              "UnLockFile",
214                                                                              "CreateTemporary",
215                                                                              "CreateNew",
216                                                                              "CheckDirectory",
217                                                                              "ProcessExit",
218                                                                              "SeekFile",
219                                                                              "LockAndRead",
220                                                                              "WriteAndUnlock",
221                                                                              null,
222                                                                              null,
223                                                                              null,
224                                                                              null,
225                                                                              null,
226                                                                              "ReadRaw",
227                                                                              "ReadMpx",
228                                                                              "ReadMpxSecondary",
229                                                                              "WriteRaw",
230                                                                              "WriteMpx",
231                                                                              null,
232                                                                              "WriteComplete",
233                                                                              null,
234                                                                              "SetInformation2",
235                                                                              "QueryInformation2",
236                                                                              "LockingAndX",
237                                                                              "Transaction",
238                                                                              "TransactionSecond",
239                                                                              "IOCtl",
240                                                                              "IOCtlSecondary",
241                                                                              "Copy",
242                                                                              "Move",
243                                                                              "Echo",
244                                                                              "WriteAndClose",
245                                                                              "OpenAndX",
246                                                                              "ReadAndX",
247                                                                              "WriteAndX",
248                                                                              null,
249                                                                              "CloseAndTreeDisconnect",
250                                                                              "Transaction2",
251                                                                              "Transaction2Secondary",
252                                                                              "FindClose2",
253                                                                              "FindNotifyClose"
254     };
255
256     private static String JavaDoc[] _cmdNames2 = { "TreeConnect",
257                                                                             "TreeDisconnect",
258                                                                             "Negotiate",
259                                                                             "SessionSetupAndX",
260                                                                             "LogoffAndX",
261                                                                             "TreeConnectAndX"
262     };
263   
264     private static String JavaDoc[] _cmdNames3 = { "DiskInformation",
265                                                                          "Search",
266                                                                          "Find",
267                                                                          "FindUnique"
268     };
269
270     private static String JavaDoc[] _cmdNames4 = { "NTTransact",
271                                                                          "NTTransactSecondary",
272                                                                          "NTCreateAndX",
273                                                                          null,
274                                                                          "NTCancel"
275     };
276
277     private static String JavaDoc[] _cmdNames5 = { "OpenPrintFile",
278                                                                          "WritePrintFile",
279                                                                          "ClosePrintFile",
280                                                                          "GetPrintQueue"
281     };
282
283     private static String JavaDoc[] _cmdNames6 = { "SendMessage",
284                                                                          "SendBroadcast",
285                                                                          "SendForward",
286                                                                          "CancelForward",
287                                                                          "GetMachineName",
288                                                                          "SendMultiStart",
289                                                                          "SendMultiEnd",
290                                                                          "SendMultiText"
291   };
292
293   // Transaction2 operation code names
294

295     private static String JavaDoc[] _transNames = { "Trans2Open",
296                                                                             "Trans2FindFirst",
297                                                                             "Trans2FindNext",
298                                                                             "Trans2QueryFileSys",
299                                                                             "Trans2QueryPath",
300                                                                             "Trans2SetPath",
301                                                                             "Trans2QueryFile",
302                                                                             "Trans2SetFile",
303                                                                             "Trans2CreateDirectory",
304                                                                             "Trans2SessionSetup"
305   };
306
307   // NT transaction operation code names
308

309     private static String JavaDoc[] _ntTranNames = { "", // zero not used
310
"NTTransCreate",
311                                                                              "NTTransIOCtl",
312                                                                              "NTTransSetSecurityDesc",
313                                                                              "NTTransNotifyChange",
314                                                                              "NTTransRename",
315                                                                              "NTTransQuerySecurityDesc",
316                                                                              "NTTransGetUserQuota",
317                                                                              "NTTransSetUserQuota"
318   };
319   
320   /**
321      * Return an SMB command as a string
322      *
323      * @param cmd int
324      * @return String
325      */

326     public static final String JavaDoc getCommandName(int cmd)
327     {
328
329         // Get the command name
330

331         String JavaDoc cmdName = "";
332
333         if (cmd >= 0 && cmd < _cmdNames1.length)
334         {
335
336             // Get the command name from the main name table
337

338             cmdName = _cmdNames1[cmd];
339         }
340         else
341         {
342
343             // Mask the command to determine the command table to index
344

345             int cmdTop = cmd & 0x00F0;
346
347             switch (cmd & 0x00F0)
348             {
349             case 0x70:
350                 cmdName = _cmdNames2[cmd - 0x70];
351                 break;
352             case 0x80:
353                 cmdName = _cmdNames3[cmd - 0x80];
354                 break;
355             case 0xA0:
356                 cmdName = _cmdNames4[cmd - 0xA0];
357                 break;
358             case 0xC0:
359                 cmdName = _cmdNames5[cmd - 0xC0];
360                 break;
361             case 0xD0:
362                 cmdName = _cmdNames6[cmd - 0xD0];
363                 break;
364             default:
365                 cmdName = "0x" + Integer.toHexString(cmd);
366                 break;
367             }
368         }
369
370         // Return the command name string
371

372         return cmdName;
373     }
374
375     /**
376      * Return a transaction code as a string
377      *
378      * @param opcode int
379      * @return String
380      */

381     public final static String JavaDoc getTransactionName(int opcode)
382     {
383
384         // Range check the opcode
385

386         String JavaDoc opcodeName = "";
387
388         if (opcode >= 0 && opcode < _transNames.length)
389             opcodeName = _transNames[opcode];
390         return opcodeName;
391     }
392
393     /**
394      * Return an NT transation code as a string
395      *
396      * @param opcode int
397      * @return String
398      */

399     public final static String JavaDoc getNTTransationName(int opcode)
400     {
401
402         // Range check the opcode
403

404         String JavaDoc opcodeName = "";
405
406         if (opcode >= 0 && opcode < _ntTranNames.length)
407             opcodeName = _ntTranNames[opcode];
408         return opcodeName;
409     }
410 }
Popular Tags