KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > smb > server > SMBPacket


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.server;
18
19 import org.alfresco.filesys.netbios.NetBIOSSession;
20 import org.alfresco.filesys.netbios.RFCNetBIOSProtocol;
21 import org.alfresco.filesys.smb.PacketType;
22 import org.alfresco.filesys.smb.SMBStatus;
23 import org.alfresco.filesys.util.DataPacker;
24
25 /**
26  * SMB packet type class
27  */

28 public class SMBPacket
29 {
30
31     // SMB packet offsets, assuming an RFC NetBIOS transport
32

33     public static final int SIGNATURE = RFCNetBIOSProtocol.HEADER_LEN;
34     public static final int COMMAND = 4 + RFCNetBIOSProtocol.HEADER_LEN;
35     public static final int ERRORCODE = 5 + RFCNetBIOSProtocol.HEADER_LEN;
36     public static final int ERRORCLASS = 5 + RFCNetBIOSProtocol.HEADER_LEN;
37     public static final int ERROR = 7 + RFCNetBIOSProtocol.HEADER_LEN;
38     public static final int FLAGS = 9 + RFCNetBIOSProtocol.HEADER_LEN;
39     public static final int FLAGS2 = 10 + RFCNetBIOSProtocol.HEADER_LEN;
40     public static final int PIDHIGH = 12 + RFCNetBIOSProtocol.HEADER_LEN;
41     public static final int SID = 18 + RFCNetBIOSProtocol.HEADER_LEN;
42     public static final int SEQNO = 20 + RFCNetBIOSProtocol.HEADER_LEN;
43     public static final int TID = 24 + RFCNetBIOSProtocol.HEADER_LEN;
44     public static final int PID = 26 + RFCNetBIOSProtocol.HEADER_LEN;
45     public static final int UID = 28 + RFCNetBIOSProtocol.HEADER_LEN;
46     public static final int MID = 30 + RFCNetBIOSProtocol.HEADER_LEN;
47     public static final int WORDCNT = 32 + RFCNetBIOSProtocol.HEADER_LEN;
48     public static final int ANDXCOMMAND = 33 + RFCNetBIOSProtocol.HEADER_LEN;
49     public static final int ANDXRESERVED = 34 + RFCNetBIOSProtocol.HEADER_LEN;
50     public static final int PARAMWORDS = 33 + RFCNetBIOSProtocol.HEADER_LEN;
51
52     // SMB packet header length for a transaction type request
53

54     public static final int TRANS_HEADERLEN = 66 + RFCNetBIOSProtocol.HEADER_LEN;
55
56     // Minimum receive length for a valid SMB packet
57

58     public static final int MIN_RXLEN = 32;
59
60     // Default buffer size to allocate for SMB packets
61

62     public static final int DEFAULT_BUFSIZE = 4096;
63
64     // Flag bits
65

66     public static final int FLG_SUBDIALECT = 0x01;
67     public static final int FLG_CASELESS = 0x08;
68     public static final int FLG_CANONICAL = 0x10;
69     public static final int FLG_OPLOCK = 0x20;
70     public static final int FLG_NOTIFY = 0x40;
71     public static final int FLG_RESPONSE = 0x80;
72
73     // Flag2 bits
74

75     public static final int FLG2_LONGFILENAMES = 0x0001;
76     public static final int FLG2_EXTENDEDATTRIB = 0x0002;
77     public static final int FLG2_SECURITYSIGS = 0x0004;
78     public static final int FLG2_LONGNAMESUSED = 0x0040;
79     public static final int FLG2_EXTENDNEGOTIATE = 0x0800;
80     public static final int FLG2_DFSRESOLVE = 0x1000;
81     public static final int FLG2_READIFEXE = 0x2000;
82     public static final int FLG2_LONGERRORCODE = 0x4000;
83     public static final int FLG2_UNICODE = 0x8000;
84
85     // Security mode bits
86

87     public static final int SEC_USER = 0x0001;
88     public static final int SEC_ENCRYPT = 0x0002;
89
90     // Raw mode bits
91

92     public static final int RAW_READ = 0x0001;
93     public static final int RAW_WRITE = 0x0002;
94
95     // SMB packet buffer
96

97     private byte[] m_smbbuf;
98
99     // Packet type
100

101     private int m_pkttype;
102
103     // Current byte area pack/unpack position
104

105     protected int m_pos;
106     protected int m_endpos;
107
108     /**
109      * Default constructor
110      */

111     public SMBPacket()
112     {
113         m_smbbuf = new byte[DEFAULT_BUFSIZE];
114         InitializeBuffer();
115     }
116
117     /**
118      * Construct an SMB packet using the specified packet buffer.
119      *
120      * @param buf SMB packet buffer.
121      */

122     public SMBPacket(byte[] buf)
123     {
124         m_smbbuf = buf;
125     }
126
127     /**
128      * Construct an SMB packet of the specified size.
129      *
130      * @param siz Size of SMB packet buffer to allocate.
131      */

132     public SMBPacket(int siz)
133     {
134         m_smbbuf = new byte[siz];
135         InitializeBuffer();
136     }
137
138     /**
139      * Copy constructor
140      *
141      * @param pkt SMBPacket
142      */

143     public SMBPacket(SMBPacket pkt)
144     {
145
146         // Allocate a new buffer
147

148         m_smbbuf = new byte[pkt.getBuffer().length];
149
150         // Copy the valid data to the new packet
151

152         System.arraycopy(pkt.getBuffer(), 0, m_smbbuf, 0, pkt.getLength());
153     }
154
155     /**
156      * Clear the data byte count
157      */

158     public final void clearBytes()
159     {
160         int offset = getByteOffset() - 2;
161         DataPacker.putIntelShort(0, m_smbbuf, offset);
162     }
163
164     /**
165      * Dump the SMB packet to the debug stream
166      */

167     public final void DumpPacket()
168     {
169     }
170
171     /**
172      * Check if the error class/code match the specified error/class
173      *
174      * @param errClass int
175      * @param errCode int
176      * @return boolean
177      */

178     public final boolean equalsError(int errClass, int errCode)
179     {
180         if (getErrorClass() == errClass && getErrorCode() == errCode)
181             return true;
182         return false;
183     }
184
185     /**
186      * Get the secondary command code
187      *
188      * @return Secondary command code
189      */

190     public final int getAndXCommand()
191     {
192         return (int) (m_smbbuf[ANDXCOMMAND] & 0xFF);
193     }
194
195     /**
196      * Return the byte array used for the SMB packet
197      *
198      * @return Byte array used for the SMB packet.
199      */

200     public final byte[] getBuffer()
201     {
202         return m_smbbuf;
203     }
204
205     /**
206      * Return the total buffer size available to the SMB request
207      *
208      * @return Total SMB buffer length available.
209      */

210     public final int getBufferLength()
211     {
212         return m_smbbuf.length - RFCNetBIOSProtocol.HEADER_LEN;
213     }
214
215     /**
216      * Get the data byte count for the SMB packet
217      *
218      * @return Data byte count
219      */

220     public final int getByteCount()
221     {
222
223         // Calculate the offset of the byte count
224

225         int pos = PARAMWORDS + (2 * getParameterCount());
226         return (int) DataPacker.getIntelShort(m_smbbuf, pos);
227     }
228
229     /**
230      * Get the data byte area offset within the SMB packet
231      *
232      * @return Data byte offset within the SMB packet.
233      */

234     public final int getByteOffset()
235     {
236
237         // Calculate the offset of the byte buffer
238

239         int pCnt = getParameterCount();
240         int pos = WORDCNT + (2 * pCnt) + 3;
241         return pos;
242     }
243
244     /**
245      * Get the SMB command
246      *
247      * @return SMB command code.
248      */

249     public final int getCommand()
250     {
251         return (int) (m_smbbuf[COMMAND] & 0xFF);
252     }
253
254     /**
255      * Determine if normal or long error codes have been returned
256      *
257      * @return boolean
258      */

259     public final boolean hasLongErrorCode()
260     {
261         if ((getFlags2() & FLG2_LONGERRORCODE) == 0)
262             return false;
263         return true;
264     }
265
266     /**
267      * Check if the packet contains ASCII or Unicode strings
268      *
269      * @return boolean
270      */

271     public final boolean isUnicode()
272     {
273         return (getFlags2() & FLG2_UNICODE) != 0 ? true : false;
274     }
275
276     /**
277      * Check if the packet is using caseless filenames
278      *
279      * @return boolean
280      */

281     public final boolean isCaseless()
282     {
283         return (getFlags() & FLG_CASELESS) != 0 ? true : false;
284     }
285
286     /**
287      * Check if long file names are being used
288      *
289      * @return boolean
290      */

291     public final boolean isLongFileNames()
292     {
293         return (getFlags2() & FLG2_LONGFILENAMES) != 0 ? true : false;
294     }
295
296     /**
297      * Check if long error codes are being used
298      *
299      * @return boolean
300      */

301     public final boolean isLongErrorCode()
302     {
303         return (getFlags2() & FLG2_LONGERRORCODE) != 0 ? true : false;
304     }
305
306     /**
307      * Get the SMB error class
308      *
309      * @return SMB error class.
310      */

311     public final int getErrorClass()
312     {
313         return (int) m_smbbuf[ERRORCLASS] & 0xFF;
314     }
315
316     /**
317      * Get the SMB error code
318      *
319      * @return SMB error code.
320      */

321     public final int getErrorCode()
322     {
323         return (int) m_smbbuf[ERROR] & 0xFF;
324     }
325
326     /**
327      * Get the SMB flags value.
328      *
329      * @return SMB flags value.
330      */

331     public final int getFlags()
332     {
333         return (int) m_smbbuf[FLAGS] & 0xFF;
334     }
335
336     /**
337      * Get the SMB flags2 value.
338      *
339      * @return SMB flags2 value.
340      */

341     public final int getFlags2()
342     {
343         return (int) DataPacker.getIntelShort(m_smbbuf, FLAGS2);
344     }
345
346     /**
347      * Calculate the total used packet length.
348      *
349      * @return Total used packet length.
350      */

351     public final int getLength()
352     {
353         return (getByteOffset() + getByteCount()) - SIGNATURE;
354     }
355
356     /**
357      * Get the long SMB error code
358      *
359      * @return Long SMB error code.
360      */

361     public final int getLongErrorCode()
362     {
363         return DataPacker.getIntelInt(m_smbbuf, ERRORCODE);
364     }
365
366     /**
367      * Get the multiplex identifier.
368      *
369      * @return Multiplex identifier.
370      */

371     public final int getMultiplexId()
372     {
373         return DataPacker.getIntelShort(m_smbbuf, MID);
374     }
375
376     /**
377      * Get a parameter word from the SMB packet.
378      *
379      * @param idx Parameter index (zero based).
380      * @return Parameter word value.
381      * @exception java.lang.IndexOutOfBoundsException If the parameter index is out of range.
382      */

383     public final int getParameter(int idx) throws java.lang.IndexOutOfBoundsException JavaDoc
384     {
385
386         // Range check the parameter index
387

388         if (idx > getParameterCount())
389             throw new java.lang.IndexOutOfBoundsException JavaDoc();
390
391         // Calculate the parameter word offset
392

393         int pos = WORDCNT + (2 * idx) + 1;
394         return (int) (DataPacker.getIntelShort(m_smbbuf, pos) & 0xFFFF);
395     }
396
397     /**
398      * Get the specified parameter words, as an int value.
399      *
400      * @param idx Parameter index (zero based).
401      * @param val Parameter value.
402      */

403     public final int getParameterLong(int idx)
404     {
405         int pos = WORDCNT + (2 * idx) + 1;
406         return DataPacker.getIntelInt(m_smbbuf, pos);
407     }
408
409     /**
410      * Get the parameter count
411      *
412      * @return Parameter word count.
413      */

414     public final int getParameterCount()
415     {
416         return (int) m_smbbuf[WORDCNT];
417     }
418
419     /**
420      * Get the process indentifier (PID)
421      *
422      * @return Process identifier value.
423      */

424     public final int getProcessId()
425     {
426         return DataPacker.getIntelShort(m_smbbuf, PID);
427     }
428
429     /**
430      * Get the tree identifier (TID)
431      *
432      * @return Tree identifier (TID)
433      */

434     public final int getTreeId()
435     {
436         return DataPacker.getIntelShort(m_smbbuf, TID);
437     }
438
439     /**
440      * Get the user identifier (UID)
441      *
442      * @return User identifier (UID)
443      */

444     public final int getUserId()
445     {
446         return DataPacker.getIntelShort(m_smbbuf, UID);
447     }
448
449     /**
450      * Initialize the SMB packet buffer.
451      */

452     private final void InitializeBuffer()
453     {
454
455         // Set the packet signature
456

457         m_smbbuf[SIGNATURE] = (byte) 0xFF;
458         m_smbbuf[SIGNATURE + 1] = (byte) 'S';
459         m_smbbuf[SIGNATURE + 2] = (byte) 'M';
460         m_smbbuf[SIGNATURE + 3] = (byte) 'B';
461     }
462
463     /**
464      * Determine if this packet is an SMB response, or command packet
465      *
466      * @return true if this SMB packet is a response, else false
467      */

468     public final boolean isResponse()
469     {
470         int resp = getFlags();
471         if ((resp & FLG_RESPONSE) != 0)
472             return true;
473         return false;
474     }
475
476     /**
477      * Check if the response packet is valid, ie. type and flags
478      *
479      * @return true if the SMB packet is a response packet and the response is valid, else false.
480      */

481     public final boolean isValidResponse()
482     {
483
484         // Check if this is a response packet, and the correct type of packet
485

486         if (isResponse() && getCommand() == m_pkttype)
487         {
488
489             // Check if standard error codes or NT 32-bit error codes are being used
490

491             if ((getFlags2() & FLG2_LONGERRORCODE) == 0)
492             {
493                 if (getErrorClass() == SMBStatus.Success)
494                     return true;
495             }
496             else if (getLongErrorCode() == SMBStatus.NTSuccess)
497                 return true;
498         }
499         return false;
500     }
501
502     /**
503      * Pack a byte (8 bit) value into the byte area
504      *
505      * @param val byte
506      */

507     public final void packByte(byte val)
508     {
509         m_smbbuf[m_pos++] = val;
510     }
511
512     /**
513      * Pack a byte (8 bit) value into the byte area
514      *
515      * @param val int
516      */

517     public final void packByte(int val)
518     {
519         m_smbbuf[m_pos++] = (byte) val;
520     }
521
522     /**
523      * Pack the specified bytes into the byte area
524      *
525      * @param byts byte[]
526      * @param len int
527      */

528     public final void packBytes(byte[] byts, int len)
529     {
530         for (int i = 0; i < len; i++)
531             m_smbbuf[m_pos++] = byts[i];
532     }
533
534     /**
535      * Pack a string using either ASCII or Unicode into the byte area
536      *
537      * @param str String
538      * @param uni boolean
539      */

540     public final void packString(String JavaDoc str, boolean uni)
541     {
542
543         // Check for Unicode or ASCII
544

545         if (uni)
546         {
547
548             // Word align the buffer position, pack the Unicode string
549

550             m_pos = DataPacker.wordAlign(m_pos);
551             DataPacker.putUnicodeString(str, m_smbbuf, m_pos, true);
552             m_pos += (str.length() * 2) + 2;
553         }
554         else
555         {
556
557             // Pack the ASCII string
558

559             DataPacker.putString(str, m_smbbuf, m_pos, true);
560             m_pos += str.length() + 1;
561         }
562     }
563
564     /**
565      * Pack a word (16 bit) value into the byte area
566      *
567      * @param val int
568      */

569     public final void packWord(int val)
570     {
571         DataPacker.putIntelShort(val, m_smbbuf, m_pos);
572         m_pos += 2;
573     }
574
575     /**
576      * Pack a 32 bit integer value into the byte area
577      *
578      * @param val int
579      */

580     public final void packInt(int val)
581     {
582         DataPacker.putIntelInt(val, m_smbbuf, m_pos);
583         m_pos += 4;
584     }
585
586     /**
587      * Pack a long integer (64 bit) value into the byte area
588      *
589      * @param val long
590      */

591     public final void packLong(long val)
592     {
593         DataPacker.putIntelLong(val, m_smbbuf, m_pos);
594         m_pos += 8;
595     }
596
597     /**
598      * Return the current byte area buffer position
599      *
600      * @return int
601      */

602     public final int getPosition()
603     {
604         return m_pos;
605     }
606
607     /**
608      * Unpack a byte value from the byte area
609      *
610      * @return int
611      */

612     public final int unpackByte()
613     {
614         return (int) m_smbbuf[m_pos++];
615     }
616
617     /**
618      * Unpack a block of bytes from the byte area
619      *
620      * @param len int
621      * @return byte[]
622      */

623     public final byte[] unpackBytes(int len)
624     {
625         if (len <= 0)
626             return null;
627
628         byte[] buf = new byte[len];
629         System.arraycopy(m_smbbuf, m_pos, buf, 0, len);
630         m_pos += len;
631         return buf;
632     }
633
634     /**
635      * Unpack a word (16 bit) value from the byte area
636      *
637      * @return int
638      */

639     public final int unpackWord()
640     {
641         int val = DataPacker.getIntelShort(m_smbbuf, m_pos);
642         m_pos += 2;
643         return val;
644     }
645
646     /**
647      * Unpack an integer (32 bit) value from the byte/parameter area
648      *
649      * @return int
650      */

651     public final int unpackInt()
652     {
653         int val = DataPacker.getIntelInt(m_smbbuf, m_pos);
654         m_pos += 4;
655         return val;
656     }
657
658     /**
659      * Unpack a long integer (64 bit) value from the byte area
660      *
661      * @return long
662      */

663     public final long unpackLong()
664     {
665         long val = DataPacker.getIntelLong(m_smbbuf, m_pos);
666         m_pos += 8;
667         return val;
668     }
669
670     /**
671      * Unpack a string from the byte area
672      *
673      * @param uni boolean
674      * @return String
675      */

676     public final String JavaDoc unpackString(boolean uni)
677     {
678
679         // Check for Unicode or ASCII
680

681         String JavaDoc ret = null;
682
683         if (uni)
684         {
685
686             // Word align the current buffer position
687

688             m_pos = DataPacker.wordAlign(m_pos);
689             ret = DataPacker.getUnicodeString(m_smbbuf, m_pos, 255);
690             if (ret != null)
691                 m_pos += (ret.length() * 2) + 2;
692         }
693         else
694         {
695
696             // Unpack the ASCII string
697

698             ret = DataPacker.getString(m_smbbuf, m_pos, 255);
699             if (ret != null)
700                 m_pos += ret.length() + 1;
701         }
702
703         // Return the string
704

705         return ret;
706     }
707
708     /**
709      * Unpack a string from the byte area
710      *
711      * @param len int
712      * @param uni boolean
713      * @return String
714      */

715     public final String JavaDoc unpackString(int len, boolean uni)
716     {
717
718         // Check for Unicode or ASCII
719

720         String JavaDoc ret = null;
721
722         if (uni)
723         {
724
725             // Word align the current buffer position
726

727             m_pos = DataPacker.wordAlign(m_pos);
728             ret = DataPacker.getUnicodeString(m_smbbuf, m_pos, len);
729             if (ret != null)
730                 m_pos += (ret.length() * 2);
731         }
732         else
733         {
734
735             // Unpack the ASCII string
736

737             ret = DataPacker.getString(m_smbbuf, m_pos, len);
738             if (ret != null)
739                 m_pos += ret.length();
740         }
741
742         // Return the string
743

744         return ret;
745     }
746
747     /**
748      * Check if there is more data in the byte area
749      *
750      * @return boolean
751      */

752     public final boolean hasMoreData()
753     {
754         if (m_pos < m_endpos)
755             return true;
756         return false;
757     }
758
759     /**
760      * Receive an SMB response packet.
761      *
762      * @param sess NetBIOS session to receive the SMB packet on.
763      * @exception java.io.IOException If an I/O error occurs.
764      */

765     private final void ReceiveSMB(NetBIOSSession sess) throws java.io.IOException JavaDoc
766     {
767
768         if (sess.Receive(m_smbbuf, RFCNetBIOSProtocol.TMO) >= MIN_RXLEN)
769             return;
770
771         // Not enough data received for an SMB header
772

773         throw new java.io.IOException JavaDoc("Short NetBIOS receive");
774     }
775
776     /**
777      * Set the secondary SMB command
778      *
779      * @param cmd Secondary SMB command code.
780      */

781     public final void setAndXCommand(int cmd)
782     {
783
784         // Set the chained command packet type
785

786         m_smbbuf[ANDXCOMMAND] = (byte) cmd;
787         m_smbbuf[ANDXRESERVED] = (byte) 0;
788
789         // If the AndX command is disabled clear the offset to the chained packet
790

791         if (cmd == PacketType.NoChainedCommand)
792             setParameter(1, 0);
793     }
794
795     /**
796      * Set the data byte count for this SMB packet
797      *
798      * @param cnt Data byte count.
799      */

800     public final void setByteCount(int cnt)
801     {
802         int offset = getByteOffset() - 2;
803         DataPacker.putIntelShort(cnt, m_smbbuf, offset);
804     }
805
806     /**
807      * Set the data byte count for this SMB packet
808      */

809
810     public final void setByteCount()
811     {
812         int offset = getByteOffset() - 2;
813         int len = m_pos - getByteOffset();
814         DataPacker.putIntelShort(len, m_smbbuf, offset);
815     }
816
817     /**
818      * Set the data byte area in the SMB packet
819      *
820      * @param byts Byte array containing the data to be copied to the SMB packet.
821      */

822     public final void setBytes(byte[] byts)
823     {
824         int offset = getByteOffset() - 2;
825         DataPacker.putIntelShort(byts.length, m_smbbuf, offset);
826
827         offset += 2;
828
829         for (int idx = 0; idx < byts.length; m_smbbuf[offset + idx] = byts[idx++])
830             ;
831     }
832
833     /**
834      * Set the SMB command
835      *
836      * @param cmd SMB command code
837      */

838     public final void setCommand(int cmd)
839     {
840         m_pkttype = cmd;
841         m_smbbuf[COMMAND] = (byte) cmd;
842     }
843
844     /**
845      * Set the SMB error class.
846      *
847      * @param cl SMB error class.
848      */

849     public final void setErrorClass(int cl)
850     {
851         m_smbbuf[ERRORCLASS] = (byte) (cl & 0xFF);
852     }
853
854     /**
855      * Set the SMB error code
856      *
857      * @param sts SMB error code.
858      */

859     public final void setErrorCode(int sts)
860     {
861         m_smbbuf[ERROR] = (byte) (sts & 0xFF);
862     }
863
864     /**
865      * Set the SMB flags value.
866      *
867      * @param flg SMB flags value.
868      */

869     public final void setFlags(int flg)
870     {
871         m_smbbuf[FLAGS] = (byte) flg;
872     }
873
874     /**
875      * Set the SMB flags2 value.
876      *
877      * @param flg SMB flags2 value.
878      */

879     public final void setFlags2(int flg)
880     {
881         DataPacker.putIntelShort(flg, m_smbbuf, FLAGS2);
882     }
883
884     /**
885      * Set the multiplex identifier.
886      *
887      * @param mid Multiplex identifier
888      */

889     public final void setMultiplexId(int mid)
890     {
891         DataPacker.putIntelShort(mid, m_smbbuf, MID);
892     }
893
894     /**
895      * Set the specified parameter word.
896      *
897      * @param idx Parameter index (zero based).
898      * @param val Parameter value.
899      */

900     public final void setParameter(int idx, int val)
901     {
902         int pos = WORDCNT + (2 * idx) + 1;
903         DataPacker.putIntelShort(val, m_smbbuf, pos);
904     }
905
906     /**
907      * Set the specified parameter words.
908      *
909      * @param idx Parameter index (zero based).
910      * @param val Parameter value.
911      */

912
913     public final void setParameterLong(int idx, int val)
914     {
915         int pos = WORDCNT + (2 * idx) + 1;
916         DataPacker.putIntelInt(val, m_smbbuf, pos);
917     }
918
919     /**
920      * Set the parameter count
921      *
922      * @param cnt Parameter word count.
923      */

924     public final void setParameterCount(int cnt)
925     {
926         m_smbbuf[WORDCNT] = (byte) cnt;
927     }
928
929     /**
930      * Set the process identifier value (PID).
931      *
932      * @param pid Process identifier value.
933      */

934     public final void setProcessId(int pid)
935     {
936         DataPacker.putIntelShort(pid, m_smbbuf, PID);
937     }
938
939     /**
940      * Set the packet sequence number, for connectionless commands.
941      *
942      * @param seq Sequence number.
943      */

944     public final void setSeqNo(int seq)
945     {
946         DataPacker.putIntelShort(seq, m_smbbuf, SEQNO);
947     }
948
949     /**
950      * Set the session id.
951      *
952      * @param sid Session id.
953      */

954     public final void setSID(int sid)
955     {
956         DataPacker.putIntelShort(sid, m_smbbuf, SID);
957     }
958
959     /**
960      * Set the tree identifier (TID)
961      *
962      * @param tid Tree identifier value.
963      */

964     public final void setTreeId(int tid)
965     {
966         DataPacker.putIntelShort(tid, m_smbbuf, TID);
967     }
968
969     /**
970      * Set the user identifier (UID)
971      *
972      * @param uid User identifier value.
973      */

974     public final void setUserId(int uid)
975     {
976         DataPacker.putIntelShort(uid, m_smbbuf, UID);
977     }
978
979     /**
980      * Align the byte area pointer on an int (32bit) boundary
981      */

982     public final void alignBytePointer()
983     {
984         m_pos = DataPacker.longwordAlign(m_pos);
985     }
986
987     /**
988      * Reset the byte/parameter pointer area for packing/unpacking data items from the packet
989      */

990     public final void resetBytePointer()
991     {
992         m_pos = getByteOffset();
993         m_endpos = m_pos + getByteCount();
994     }
995
996     /**
997      * Reset the byte/parameter pointer area for packing/unpacking data items from the packet, and
998      * align the buffer on an int (32bit) boundary
999      */

1000    public final void resetBytePointerAlign()
1001    {
1002        m_pos = DataPacker.longwordAlign(getByteOffset());
1003        m_endpos = m_pos + getByteCount();
1004    }
1005
1006    /**
1007     * Reset the byte/parameter pointer area for packing/unpacking paramaters from the packet
1008     */

1009    public final void resetParameterPointer()
1010    {
1011        m_pos = PARAMWORDS;
1012    }
1013
1014    /**
1015     * Set the unpack pointer to the specified offset, for AndX processing
1016     *
1017     * @param off int
1018     * @param len int
1019     */

1020    public final void setBytePointer(int off, int len)
1021    {
1022        m_pos = off;
1023        m_endpos = m_pos + len;
1024    }
1025
1026    /**
1027     * Skip a number of bytes in the parameter/byte area
1028     *
1029     * @param cnt int
1030     */

1031    public final void skipBytes(int cnt)
1032    {
1033        m_pos += cnt;
1034    }
1035}
Popular Tags