private void Decode(byte language, byte[] data, FruByteStringType encoding) { switch (encoding) { case FruByteStringType.Binary: this.Text = IpmiSharedFunc.ByteArrayToHexString(data); break; case FruByteStringType.BcdPlus: this.Text = IpmiSharedFunc.DecodeBcdPlus(data); break; case FruByteStringType.Packed6BitAscii: data = ReplaceNonAsciiChars(data); this.Text = IpmiSharedFunc.DecodePacked6bitAscii(data); break; case FruByteStringType.Text: // replace non ASCII characters data = ReplaceNonAsciiChars(data); if ((this.Language == FruByteString.defaultLang) || (this.Language == FruByteString.EnLang)) { this.Text = System.Text.Encoding.ASCII.GetString(data).Trim(); } else { this.Text = System.Text.Encoding.Unicode.GetString(data).Trim(); } break; } }
/// <summary> /// Formats Non Time Stamped OEM SEL Records /// </summary> /// <param name="EventMessageData">Event Message Data</param> /// <param name="RecordCount">SEL Record Type</param> internal static void NonTimestampedOemSelFormat(ref SystemEventLogMessage message, byte[] messageData) { // calculate Recorded date message.EventDate = new DateTime(0000, 0, 0); message.EventVersion = MsgVersion.OEM; // SensorType, RawSensorType and EventTypeCode are not used for OEM SEL entries message.SensorType = SensorType.Reserved; message.RawSensorType = (byte)SensorType.Reserved; message.EventTypeCode = 0xFF; message.SensorNumber = 0; message.EventDir = EventDir.Assertion; if (messageData.Length >= 13) { // Allocate larger array to store OEM Non-timestamped payload message.RawPayload = new byte[13]; // Copy OEM Defined payload to the response raw payload array. Format shown in IPMI 2.0 Spec Table 32-3. Buffer.BlockCopy(messageData, 0, message.RawPayload, 0, 13); // Add the raw payload as hex string to the user return class. message.EventPayload = IpmiSharedFunc.ByteArrayToHexString(message.RawPayload); } }
/// <summary> /// Formats Time Stamped OEM SEL Records /// </summary> /// <param name="EventMessageData">Event Message Data</param> /// <param name="RecordCount">SEL Record Type</param> internal static void TimeStampedOEMSelFormat(ref SystemEventLogMessage message, byte[] messageData) { // convert byte[] to int using Shift operation int TotalSeconds = messageData[0] + (messageData[1] << 8) + (messageData[2] << 16) + (messageData[3] << 24); // calculate Recorded date message.EventDate = IpmiSharedFunc.SecondsOffSet(TotalSeconds); message.EventVersion = MsgVersion.OEM; // SensorType, RawSensorType and EventTypeCode are not used for OEM SEL entries message.SensorType = SensorType.Reserved; message.RawSensorType = (byte)SensorType.Reserved; message.EventTypeCode = 0xFF; message.SensorNumber = 0; message.EventDir = EventDir.Assertion; if (messageData.Length >= 13) { // Allocate larger array to store OEM Timestamped payload message.RawPayload = new byte[9]; // Copy Manufacturer ID and OEM Defined payload to the response raw payload array. Format shown in IPMI 2.0 Spec Table 32-2. Buffer.BlockCopy(messageData, 4, message.RawPayload, 0, 9); // Add the raw payload as hex string to the user return class. message.EventPayload = IpmiSharedFunc.ByteArrayToHexString(message.RawPayload); } }
public FruMultiRecordInfo(byte[] data) : base(data) { // default constructor this.Manufacturer = string.Empty; if (data != null) { if (data.Length >= HeaderSize) // header length is defined as 10. { this.LanguageCode = data[FruMultiRecordInfo.LanguageCodeIndex]; this.WritesRemaining = data[FruMultiRecordInfo.WritesRemainingIndex]; this.RecordTypeId = data[FruMultiRecordInfo.RecordTypeIdIndex]; this.RecordFormat = data[FruMultiRecordInfo.RecordFormatIndex]; this.RecordLength = data[FruMultiRecordInfo.RecordLengthIndex]; byte[] manufactureArray = new byte[FruMultiRecordInfo.ManufacturerLength]; Array.Copy(data, FruMultiRecordInfo.ManufacturerIndex, manufactureArray, 0, FruMultiRecordInfo.ManufacturerLength); this.Manufacturer = IpmiSharedFunc.ByteArrayToHexString(manufactureArray); // add fields if (data.Length > FieldStartIndex) { // start field offset int fieldIndex = FieldStartIndex; // abort counter. int abortCnt = 0; while (fieldIndex < data.Length || abortCnt > MaximumFields) { // data fields are limited to 63 bytes in length, as length is 6 bit encouded in FRU specification. if (data.Length >= fieldIndex + FruByteString.LengthInfo(data[fieldIndex]) && data[fieldIndex] != 0xC1) { Fields.Add(FruByteString.ReadByteString(this.LanguageCode, data, fieldIndex, out fieldIndex)); } else { // escape while as fru space has ended. break; } abortCnt++; } } } } }
/// <summary> /// Send Receive Ipmi messages /// </summary> internal override IpmiResponse IpmiSendReceive(IpmiRequest ipmiRequest, Type responseType, bool allowRetry = true) { byte[] message = ipmiRequest.GetBytes(IpmiTransport.Wmi, 0x00); // Create the response based on the provided type ConstructorInfo constructorInfo = responseType.GetConstructor(Type.EmptyTypes); IpmiResponse ipmiResponse = (IpmiResponse)constructorInfo.Invoke(new Object[0]); // Serialize the IPMI request into bytes. ManagementBaseObject ipmiRequestMessage = this.GetManagementObject(ipmiRequest.ToString(), message); // invoke new method options InvokeMethodOptions methodOptions = new InvokeMethodOptions(null, System.TimeSpan.FromMilliseconds(base.Timeout)); // management return object ManagementBaseObject ipmiResponseMessage = null; // get instance and invoke RequestResponse method foreach (ManagementObject mo in ipmi_Instance) { ipmiResponseMessage = mo.InvokeMethod(ipmi_Method, wmiPacket, methodOptions); } if (ipmiResponseMessage == null) { // Assume the request timed out. ipmiResponse.CompletionCode = 0xA3; } else { ipmiResponse.CompletionCode = (byte)ipmiResponseMessage["CompletionCode"]; if (ipmiResponse.CompletionCode == 0) { try { uint dataLenght = (uint)ipmiResponseMessage["ResponseDataSize"]; // expected to be true, as ResponseDataSize includes completionCode if (dataLenght != 0) { // extract response data array byte[] responseData = (byte[])ipmiResponseMessage["ResponseData"]; // extract response message lenght if (responseData != null) { int lenght = responseData.Length; if (this.debugEnabled) { string cmd = ipmiRequest.GetType().ToString(); IpmiSharedFunc.WriteTrace(string.Format("Command: {0} Request: {1}", cmd, IpmiSharedFunc.ByteArrayToHexString(message))); if (responseData != null) { IpmiSharedFunc.WriteTrace(string.Format("Command: {0} Response: {1}", cmd, IpmiSharedFunc.ByteArrayToHexString(responseData))); } else { IpmiSharedFunc.WriteTrace(string.Format("Request: {0} Response: null", cmd)); } } // initialize the response to set the paramaters. ipmiResponse.Initialize(IpmiTransport.Wmi, responseData, lenght, 0x00); ipmiResponseMessage = null; } else { // IpmiCannotReturnRequestedDataBytes, data lenght is greater than zero // but responseData is null. ipmiResponse.CompletionCode = 0xCA; if (this.debugEnabled) { IpmiSharedFunc.WriteTrace(string.Format("Response Lenght: {0} Response: null. Asserting 0xCA CompletionCode ", dataLenght)); } } } else { // Asserting IpmiResponseNotProvided ipmiResponse.CompletionCode = 0xCE; if (this.debugEnabled) { IpmiSharedFunc.WriteTrace(string.Format("Unable to obtain Response Data Lenght: {0} Response: null. Asserting 0xCE CompletionCode ", dataLenght)); } } } catch (Exception ex) { // Response data Invalid, data convertion failed. // unexpected error, return: ipmiResponse.CompletionCode = 0xAD; if (this.debugEnabled) { IpmiSharedFunc.WriteTrace(string.Format("Exception Source: {0} Message{1}", ex.Source.ToString(), ex.Message.ToString())); } } } else { if (this.debugEnabled) { // throw ipmi/dcmi response exception with a custom string message and the ipmi completion code IpmiSharedFunc.WriteTrace(string.Format("Completion Code: " + IpmiSharedFunc.ByteToHexString(ipmiResponse.CompletionCode))); if (ipmiResponseMessage == null) { IpmiSharedFunc.WriteTrace(string.Format("Request Type: {0} Response Packet: null Completion Code {1}", ipmiRequest.GetType().ToString(), IpmiSharedFunc.ByteToHexString(ipmiResponse.CompletionCode))); } } } } // Response to the IPMI request message. return(ipmiResponse); }
/// <summary> /// Formats System Event (Standard Range) SEL Records /// </summary> /// <param name="EventMessageData">Event Message Data</param> /// <param name="RecordCount">SEL Record Type</param> internal static void StandardSelFormat(ref SystemEventLogMessage message, byte[] messageData) { // convert data bytes from messageData byte[] to int using Shift operation int totalSeconds = TimeStampFromBytes(messageData); // calculate Recorded date message.EventDate = IpmiSharedFunc.SecondsOffSet(totalSeconds); // SEL Event Message if (Enum.IsDefined(typeof(MsgVersion), messageData[6])) { message.EventVersion = (MsgVersion)messageData[6]; } else { message.EventVersion = MsgVersion.Unknown; } // Sensor Type byte sensorType = messageData[7]; // add sensor type to attribute class if (Enum.IsDefined(typeof(SensorType), sensorType)) { message.SensorType = (SensorType)sensorType; } else { message.SensorType = SensorType.Unknown; } // add sensor type to message message.RawSensorType = messageData[7]; // add sensor number to the message class message.SensorNumber = messageData[8]; // Event Data Byte byte[] eventDataByte = IpmiSharedFunc.ByteSplit(messageData[9], new int[2] { 7, 0 }); // Event Dir. Asersion/Deserstion Bit 7 byte eventDir = eventDataByte[0]; // EventType [6:0] byte eventTypeCode = eventDataByte[1]; message.EventTypeCode = eventTypeCode; // Event Dir if (Enum.IsDefined(typeof(EventDir), eventDir)) { message.EventDir = (EventDir)eventDir; } else { message.EventDir = EventDir.Unknown; } // copy event message payload to the response raw payload array Buffer.BlockCopy(messageData, 10, message.RawPayload, 0, 3); // Add the raw payload as hex string to the user return class. message.EventPayload = IpmiSharedFunc.ByteArrayToHexString(message.RawPayload); }
/// <summary> /// Send Receive Ipmi messages /// </summary> /// <param name="request"></param> /// <param name="responseType"></param> /// <returns></returns> internal override IpmiResponse IpmiSendReceive(IpmiRequest ipmiRequest, Type responseType, bool allowRetry = true) { byte[] message = ipmiRequest.GetBytes(IpmiTransport.Wmi, 0x00); // Serialize the IPMI request into bytes. ManagementBaseObject ipmiRequestMessage = this.GetManagementObject(message); // invoke new method options InvokeMethodOptions methodOptions = new InvokeMethodOptions(null, System.TimeSpan.FromMilliseconds(base.Timeout)); // management return object ManagementBaseObject ipmiResponseMessage = null; // get instance and invoke RequestResponse method foreach (ManagementObject mo in _ipmi_Instance) { ipmiResponseMessage = mo.InvokeMethod(_ipmi_Method, wmiPacket, methodOptions); } if (ipmiResponseMessage == null) { // throw ipmi/dcmi response exception with a custom string message and the ipmi completion code throw new IpmiResponseException(); } // ipmi response completion code byte completionCode = (byte)ipmiResponseMessage["CompletionCode"]; // Create the response based on the provided type and message bytes. ConstructorInfo constructorInfo = responseType.GetConstructor(Type.EmptyTypes); IpmiResponse ipmiResponse = (IpmiResponse)constructorInfo.Invoke(new Object[0]); if (completionCode == 0) { try { // extract response data array byte[] responseData = (byte[])ipmiResponseMessage["ResponseData"]; // extract response message lenght int lenght = (int)ipmiResponseMessage["ResponseDataSize"]; // initialize the response to set the paramaters. ipmiResponse.Initialize(IpmiTransport.Wmi, responseData, lenght, 0x00); ipmiResponseMessage = null; } catch (Exception ex) { Debug.WriteLine("Exception Source: {0} Message{1}", ex.Source.ToString(), ex.Message.ToString()); } } else { // throw ipmi/dcmi response exception with a custom string message and the ipmi completion code Debug.WriteLine("Completion Code: " + IpmiSharedFunc.ByteToHexString(ipmiResponse.CompletionCode)); if (ipmiResponseMessage == null) { Debug.WriteLine("Request Type: {0} Response Packet: {1} Completion Code {2}", ipmiRequest.GetType().ToString(), IpmiSharedFunc.ByteArrayToHexString((byte[])ipmiResponseMessage["ResponseData"]), IpmiSharedFunc.ByteToHexString(ipmiResponse.CompletionCode)); } } // Response to the IPMI request message. return(ipmiResponse); }