/// <summary> /// Send message MSG_GETBLKLIST. /// </summary> /// <param name="sid">segment id.</param> /// <param name="blockRang">Block ranges client wants to get.</param> /// <param name="isVersionSupported">The version in message is supported by server or not.</param> public void SendMsgGetBlkList(byte[] sid, BLOCKRANGE[] blockRang, bool isVersionSupported) { PccrrGETBLKLISTRequestPacket packet; BLOCK_RANGE[] blockRanges = Helper.ConvertToStackBLOCKRANGEArray(blockRang); if (!isVersionSupported) { packet = this.pccrrStack.CreateMsgGetBlkListRequest(sid, blockRanges, this.cryptoAlgo, MsgType_Values.MSG_GETBLKLIST, this.protoErrorVer); } else { packet = this.pccrrStack.CreateMsgGetBlkListRequest(sid, blockRanges, this.cryptoAlgo, MsgType_Values.MSG_GETBLKLIST, this.protoVer); } this.pccrrStack.SendPacket(packet, new TimeSpan(0, 0, this.timeout)); PccrrPacket respMSG = this.pccrrStack.ExpectPacket(); if (!isVersionSupported) { PccrrNegoResponsePacket pccrrNegoResponsePacket = respMSG as PccrrNegoResponsePacket; if (pccrrNegoResponsePacket != null) { this.ReceiveMsgNegoResp(); } } else { PccrrBLKLISTResponsePacket pccrrBLKLISTResponsePacket = respMSG as PccrrBLKLISTResponsePacket; MSG_BLKLIST msgBLKLIST = pccrrBLKLISTResponsePacket.MsgBLKLIST; MESSAGE_HEADER messageHeader = pccrrBLKLISTResponsePacket.MessageHeader; TRANSPORT_RESPONSE_HEADER transportRespH = pccrrBLKLISTResponsePacket.TransportResponseHeader; RESPONSE_MESSAGE respMessage = new RESPONSE_MESSAGE(); respMessage.MESSAGEBODY = msgBLKLIST; respMessage.MESSAGEHEADER = messageHeader; respMessage.TRANSPORTRESPONSEHEADER = transportRespH; if (msgBLKLIST.BlockRanges.Length != 0) { BLOCK_RANGE blockRange = pccrrBLKLISTResponsePacket.MsgBLKLIST.BlockRanges[0]; PccrrBothRoleCaptureCode.CaptureBlockRangeRequirements(blockRange); } this.VerifyMsgBlkList(msgBLKLIST); PccrrBothRoleCaptureCode.CaptureCommonDataTypesRequirements(msgBLKLIST); this.VerifyResponseMessage(respMessage); BLOCKRANGE[] blkRanges = Helper.ConvertFromStackBLOCKRANGEArray(msgBLKLIST.BlockRanges); this.ReceiveMsgBlkList(msgBLKLIST.BlockRangeCount, blkRanges, msgBLKLIST.NextBlockIndex); } }
/// <summary> /// Capture Common Data Types structure requirements. /// </summary> /// <param name="obj">The object.</param> public static void CaptureCommonDataTypesRequirements(object obj) { if (obj is MSG_GETBLKLIST) { MSG_GETBLKLIST getBlkList = (MSG_GETBLKLIST)obj; // // Add the debug information // site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R22"); // Verify MS-PCCRR requirement: MS-PCCRR_R22 bool isVerifyR22 = getBlkList.NeededBlocksRangeCount.GetType() == typeof(uint); site.CaptureRequirementIfIsTrue( isVerifyR22, 22, @"[In Common Data Types]The protocol supports three field types: Integer (DWORD fields as defined in [MS-DTYP] section 2.2.9, transmitted in network byte order)."); // // Add the debug information // site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R23"); // Verify MS-PCCRR requirement: MS-PCCRR_R23 bool isVerifyR23 = getBlkList.NeededBlockRanges.GetType() == typeof(BLOCK_RANGE[]); site.CaptureRequirementIfIsTrue( isVerifyR23, 23, @"[In Common Data Types][The protocol supports three field types]BLOCK_RANGE_ARRAY ( (Integer [2])[count], i.e. a count-sized array of BLOCK_RANGE fields)."); // // Add the debug information // site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R24"); // Verify MS-PCCRR requirement: MS-PCCRR_R24 bool isVerifyR24 = getBlkList.SegmentID.GetType() == typeof(byte[]); site.CaptureRequirementIfIsTrue( isVerifyR24, 24, @"[In Common Data Types][The protocol supports three field types]BYTE array (BYTE[count], i.e. a count-sized array of bytes)."); // // Add the debug information // site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R33"); // Verify MS-PCCRR requirement: MS-PCCRR_R33 // if server has any of the requested block ranges. then getBlkList.NeededBlockRanges > 0, // BlockRanges is an array of BLOCK_RANGE to store BLOCK_RANGE entries. // If the lenght is larger than 0, means it contains BLOCK_RANGE entries. bool isVerifyR33 = getBlkList.NeededBlockRanges.Length > 0; site.CaptureRequirementIfIsTrue( isVerifyR33, 33, @"[In BLOCK_RANGE_ARRAY]Variable-size array containing BLOCK_RANGE entries."); // // Add the debug information // site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R34"); // Verify MS-PCCRR requirement: MS-PCCRR_R34 // If the type is BLOCK_RANGE[], means that it is declared as follows: typedef BLOCK_RANGE BLOCK_RANGE_ARRAY[]. bool isVerifyR34 = getBlkList.NeededBlockRanges.GetType() == typeof(BLOCK_RANGE[]); site.CaptureRequirementIfIsTrue( isVerifyR34, 34, @"[In BLOCK_RANGE_ARRAY]This type[BLOCK_RANGE_ARRAY] is declared as follows: typedef BLOCK_RANGE BLOCK_RANGE_ARRAY[];"); } else if (obj is MSG_BLKLIST) { MSG_BLKLIST blkList = (MSG_BLKLIST)obj; // // Add the debug information // site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R22"); // Verify MS-PCCRR requirement: MS-PCCRR_R22 bool isVerifyR22 = blkList.BlockRangeCount.GetType() == typeof(uint); site.CaptureRequirementIfIsTrue( isVerifyR22, 22, @"[In Common Data Types]The protocol supports three field types:Integer (DWORD fields as defined in [MS-DTYP] section 2.2.9, transmitted in network byte order)."); // // Add the debug information // site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R23"); // Verify MS-PCCRR requirement: MS-PCCRR_R23 bool isVerifyR23 = blkList.BlockRanges.GetType() == typeof(BLOCK_RANGE[]); site.CaptureRequirementIfIsTrue( isVerifyR23, 23, @"[In Common Data Types][The protocol supports three field types]BLOCK_RANGE_ARRAY ( (Integer [2])[count], i.e. a count-sized array of BLOCK_RANGE fields)."); // // Add the debug information // site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R24"); // Verify MS-PCCRR requirement: MS-PCCRR_R24 bool isVerifyR24 = blkList.ZeroPad.GetType() == typeof(byte[]); site.CaptureRequirementIfIsTrue( isVerifyR24, 24, @"[In Common Data Types][The protocol supports three field types]BYTE array (BYTE[count], i.e. a count-sized array of bytes)."); // // Add the debug information // site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R33"); // Verify MS-PCCRR requirement: MS-PCCRR_R33 // if server has any of the requested block ranges. then blkList.BlockRanges.Length > 0, // BlockRanges is an array of BLOCK_RANGE to store BLOCK_RANGE entries. // If the lenght is larger than 0, means it contains BLOCK_RANGE entries. bool isVerifyR33 = blkList.BlockRanges.Length >= 0; site.CaptureRequirementIfIsTrue( isVerifyR33, 33, @"[In BLOCK_RANGE_ARRAY]Variable-size array containing BLOCK_RANGE entries."); // // Add the debug information // site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R34"); // Verify MS-PCCRR requirement: MS-PCCRR_R34 // If the type is BLOCK_RANGE[], means that it is declared as follows: typedef BLOCK_RANGE BLOCK_RANGE_ARRAY[]. bool isVerifyR34 = blkList.BlockRanges.GetType() == typeof(BLOCK_RANGE[]); site.CaptureRequirementIfIsTrue( isVerifyR34, 34, @"[In BLOCK_RANGE_ARRAY]This type[BLOCK_RANGE_ARRAY] is declared as follows:typedef BLOCK_RANGE BLOCK_RANGE_ARRAY[];"); } }
/// <summary> /// Capture MSG_BLKLIST structure related requirements. /// </summary> /// <param name="blkList">MSG_BLKLIST object</param> private void VerifyMsgBlkList(MSG_BLKLIST blkList) { // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R136"); // Verify MS-PCCRR requirement: MS-PCCRR_R136 Site.CaptureRequirementIfAreEqual <uint>( (uint)blkList.SegmentId.Length, blkList.SizeOfSegmentId, 136, @"[In MSG_BLKLIST]SizeOfSegmentId (4 bytes): The size, in bytes, of the subsequent SegmentId field."); if (null != blkList.ZeroPad) { bool isAllZero = true; // If the length is zero, the flag will remain in true // else, the bytes will be checked in foreach statements foreach (byte b in blkList.ZeroPad) { if (b != 0) { isAllZero = false; break; } } // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R140"); // Verify MS-PCCRR requirement: MS-PCCRR_R140 bool isVerifyR140 = isAllZero; Site.CaptureRequirementIfIsTrue( isVerifyR140, 140, @"[In MSG_BLKLIST][ZeroPad (variable)]Each byte's value MUST be set to zero."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R139"); // Verify MS-PCCRR requirement: MS-PCCRR_R139 bool isVerifyR139 = blkList.ZeroPad.Length >= 0 && blkList.ZeroPad.Length <= 3; Site.CaptureRequirementIfIsTrue( isVerifyR139, 139, @"[In MSG_BLKLIST]ZeroPad (variable): A sequence of N bytes added (only as needed) to restore 4-byte alignment, where 0 <= N <= 3."); if (null != blkList.BlockRanges && blkList.BlockRangeCount != 0) { // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R141"); // Verify MS-PCCRR requirement: MS-PCCRR_R141 Site.CaptureRequirementIfAreEqual <uint>( (uint)blkList.BlockRanges.Length, blkList.BlockRangeCount, 141, @"[In MSG_BLKLIST]BlockRangeCount (4 bytes): Number of items in the subsequent block range array."); } } }