示例#1
0
        /// <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);
            }
        }
示例#2
0
 internal DiscreteEvent(EventLogMsgType MsgType, byte sensorType, byte eventType, byte[] eventPayload)
     : base(MsgType, sensorType, eventType, eventPayload)
 {
     if (MsgType == EventLogMsgType.SensorSpecific &&
         sensorType == 42)    // add exception for user Id
     {
         byte[] evtData2 = IpmiSharedFunc.ByteSplit(eventPayload[1], new int[2] {
             6, 0
         });
         evtByte2Severity = evtData2[0];
         evtByte2Reading  = evtData2[1];
     }
     else if (MsgType == EventLogMsgType.SensorSpecific &&
              sensorType == 43) // add exception for Version Change Type
     {
         evtByte2Reading = eventPayload[1];
     }
     else if (MsgType == EventLogMsgType.SensorSpecific &&
              sensorType == 40 && base.Offset == 5) // add exception for FRU device Id
     {
         // swap event payload with payload 2.
         byte temp = eventPayload[1];
         eventPayload[1] = eventPayload[2];
         eventPayload[2] = temp;
     }
     else
     {
         byte[] evtData2 = IpmiSharedFunc.ByteSplit(eventPayload[1], new int[2] {
             4, 0
         });
         evtByte2Severity = evtData2[0];
         evtByte2Reading  = evtData2[1];
     }
 }
        /// <summary>
        /// Write Fru Data Command.  Note:
        ///     The command writes the specified byte or word to the FRU Inventory Info area. This is a ‘low level’ direct
        ///     interface to a non-volatile storage area. The interface does not interpret or check any semantics or
        ///     formatting for the data being written.  The offset used in this command is a ‘logical’ offset that may or may not
        ///     correspond to the physical address. For example, FRU information could be kept in FLASH at physical address 1234h,
        ///     however offset 0000h would still be used with this command to access the start of the FRU information.
        ///
        ///     IPMI FRU device data (devices that are formatted per [FRU]) as well as processor and DIMM FRU data always starts
        ///     from offset 0000h unless otherwise noted.
        /// </summary>
        public virtual WriteFruDevice WriteFruDevice(int deviceId, ushort offset, byte[] payload)
        {
            byte loOffset;
            byte hiOffset;

            // split address into hi and lo bytes.
            IpmiSharedFunc.SplitWord(offset, out loOffset, out hiOffset);

            WriteFruDataResponse fruResponse =
                this.IpmiSendReceive <WriteFruDataResponse>(new WriteFruDataRequest(loOffset, hiOffset, payload)
            {
                DeviceId = (byte)deviceId
            });

            WriteFruDevice response = new WriteFruDevice(fruResponse.CompletionCode);

            if (fruResponse.CompletionCode == 0)
            {
                response.SetParamaters(new byte[1] {
                    fruResponse.CountWritten
                });
            }

            return(response);
        }
示例#4
0
        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;
            }
        }
示例#5
0
        /// <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);
            }
        }
示例#6
0
        /// <summary>
        /// Convert the IPMI request meeting into a byte stream for transmission
        /// to the BMC over Serial.
        /// [Byte 0]    [Byte 1]    [Byte 2]    [Byte 3]
        /// [StrChar]   [rsAddr]    [netFn]     [chksum]
        /// [Byte 4]    [Byte 5]    [Byte 6]    [Byte 7]    [Byte 8]    [Byte 9]
        /// [rqAddr]    [rqSeq]     [cmd]       [payload]   [cksum]     [stop]
        /// </summary>
        /// <param name="IpmiRqSeq">Sequence id for message.</param>
        /// <returns>byte array representing the Serial data to send.</returns>
        internal byte[] GetBytes(IpmiTransport transport, byte IpmiRqSeq)
        {
            // payload lenght
            int dataLength = GetPayloadLenght();

            // payload bytes
            byte[] payload = GetPayload(dataLength);

            // response message lenght
            int messageLength = dataLength;

            if (transport == IpmiTransport.Serial)
            {
                // Add 9 bytes for 7 byte header and start + stop byte
                // 09 bytes =   byte[1] start, byte[2] rsAdd, byte[3] netFnAndrqLun, byte[4] checksum1
                //              byte[5] rqAddr, byte[6] rqSeqAndrsLun, byte[7] command, byte[x] payload
                //              byte[8] checksum, byte[09] stop.
                messageLength += 9;
            }

            byte[] messagedata = new byte[messageLength];

            if (transport == IpmiTransport.Serial)
            {
                // Step 1. Add Message Header.
                #region Message header

                messagedata[1] = 0x20;                                 // rsAddr
                messagedata[2] = (byte)((byte)this.IpmiFunction << 2); // netFN
                messagedata[3] = 0x00;                                 // checksum zero'd for now.  Set after data.
                messagedata[4] = 0x81;                                 // for serial can be 0x8F;
                messagedata[5] = (byte)((byte)IpmiRqSeq << 2);         // rqSeq/rqLun
                messagedata[6] = (byte)this.IpmiCommand;               // cmd

                #endregion

                // Step 2. Add payload Data.
                // Add ipmi message data
                // dataIndex + 7 offsets encapsulated ipmi message header & start charactor
                Buffer.BlockCopy(payload, 0, messagedata, 7, payload.Length);

                // Step 3. Add Message Checksum
                #region Message checksum

                // Set checksum 1: Byte 0 = Start Char, Byte 1 = rsAdd,
                // Byte 2 = netFn, Byte 3 = Checksum
                messagedata[3] = IpmiSharedFunc.TwoComplementChecksum(1, 3, messagedata);

                // Ipmi message encapsulation format checksum 2
                // checksum 2 begins after checksum 1.
                // checksum 2 calculated from rqAddr to end of data lenght.
                messagedata[(7 + dataLength)] = IpmiSharedFunc.TwoComplementChecksum(4, (7 + dataLength), messagedata);

                #endregion
            }

            return(messagedata);
        }
示例#7
0
 internal OemEvent(EventLogMsgType MsgType, byte sensorType, byte eventType, byte[] eventPayload)
     : base(MsgType, sensorType, eventType, eventPayload)
 {
     byte[] evtData2 = IpmiSharedFunc.ByteSplit(eventPayload[1], new int[2] {
         4, 3
     });
     evtByte2Severity = evtData2[0];
     evtByte2Reading  = evtData2[1];
 }
示例#8
0
        protected EventData(EventLogMsgType MsgType, byte sensorType, byte eventTypeCode, byte[] payload)
        {
            this.messageType  = MsgType;
            this.eventType    = Convert.ToInt32(eventTypeCode);
            this.eventPayload = payload;
            this.sensorType   = Convert.ToInt32(sensorType);

            byte[] evtData1 = IpmiSharedFunc.ByteSplit(eventPayload[0], new int[3] {
                6, 4, 0
            });

            this.evtData1Part1 = Convert.ToInt32(evtData1[0]);
            this.evtData1Part2 = Convert.ToInt32(evtData1[1]);
            this.offset        = Convert.ToInt32(evtData1[2]);
        }
示例#9
0
        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>
        /// Reads raw fru data, and returns a byte array.
        /// </summary>
        public virtual byte[] ReadFruDevice(int deviceId, ushort offset, byte readCount)
        {
            byte loOffset;
            byte hiOffset;

            // split address into hi and lo bytes.
            IpmiSharedFunc.SplitWord(offset, out loOffset, out hiOffset);

            GetFruDataResponse fruResponse =
                this.IpmiSendReceive <GetFruDataResponse>(new GetFruDataRequest(loOffset, hiOffset, readCount)
            {
                DeviceId = (byte)deviceId
            });

            return(fruResponse.DataReturned);
        }
        /// <summary>
        /// Get Fru Inventory Area
        /// </summary>
        public virtual FruInventoryArea GetFruInventoryArea(byte deviceId = 0)
        {
            GetFruInventoryAreaInfoResponse response = (GetFruInventoryAreaInfoResponse)this.IpmiSendReceive(
                new GetFruInventoryAreaInfoRequest(deviceId), typeof(GetFruInventoryAreaInfoResponse));

            FruInventoryArea fruArea = new FruInventoryArea(response.CompletionCode);

            if (response.CompletionCode == 0)
            {
                fruArea.fruSize = IpmiSharedFunc.GetShort(response.OffSetLS, response.OffSetMS);
                if ((byte)(response.AccessType & 0x01) == 0x01)
                {
                    fruArea.accessedByBytes = false;
                }
            }

            return(fruArea);
        }
        /// <summary>
        /// Send sync Bridge Command
        /// </summary>
        /// <param name="channel">Channel to send command (Intel ME = 6)</param>
        /// <param name="slaveId">Channel Slave Id</param>
        /// /// <param name="trackRequest">Trace Message</param>
        /// <param name="messageData">Message payload</param>
        public virtual SendNodeMangerMessage SendNodeManagerRequest(byte channel, byte slaveId, bool trackRequest, NodeManagerRequest requestMessage, Type responseMessage)
        {
            byte rqSeq = NodeManagerRqSeq();

            byte[] nodeManagerMessage = requestMessage.GetNodeManagerBytes(slaveId, rqSeq, trackRequest);

            SendMessageResponse msgResponse = (SendMessageResponse)this.IpmiSendReceive(
                new SendMessageRequest(channel, trackRequest, nodeManagerMessage),
                typeof(SendMessageResponse));

            SendNodeMangerMessage response = new SendNodeMangerMessage(msgResponse.CompletionCode);

            if (response.CompletionCode == 0x00)
            {
                // Create the response based on the provided type.
                ConstructorInfo     constructorInfo     = responseMessage.GetConstructor(Type.EmptyTypes);
                NodeManagerResponse nodeManagerResponse = (NodeManagerResponse)constructorInfo.Invoke(new Object[0]);

                // set the message data.
                response.MessageData = msgResponse.MessageData;

                try
                {
                    nodeManagerResponse.InitializeNodeManager(msgResponse.MessageData, msgResponse.MessageData.Length, rqSeq);
                    response.Response = nodeManagerResponse;
                }
                catch (Exception ex)
                {
                    IpmiSharedFunc.WriteTrace(string.Format("Send Message error converting payload. Exception occured converting packet: {0}", ex));

                    // set an exception code for invalid data in ipmi data field, as the packet could
                    nodeManagerResponse.CompletionCode = 0xD6; // IpmiCmdFailedIllegalParameter
                }
            }

            return(response);
        }
示例#13
0
        /// <summary>
        /// DCMI Get Power Reading Command
        /// </summary>
        public virtual List <PowerReading> GetAdvancedPowerReading()
        {
            // Return item
            List <PowerReading> returnlist = new List <PowerReading>();

            // Index Offset of 0 into ResponseData
            int index = 0;

            // Get DCMI Capabilities to check if power management is supported, if so
            // check if advanced power stats are supported.
            GetDcmiCapabilitiesResponse response = (GetDcmiCapabilitiesResponse)this.IpmiSendReceive(
                new GetDcmiCapabilitiesRequest(0x01), typeof(GetDcmiCapabilitiesResponse));

            byte[] powerSupport = new byte[2] {
                0x00, 0x00
            };

            if (response.CompletionCode == 0)
            {
                // power management support byte array.  response.ResponseData[1] = platform capabilities.
                // [7-1]  Reserved, Power Management.
                byte[] tempArray = IpmiSharedFunc.ByteSplit(response.ResponseData[1], new int[2] {
                    1, 0
                });
                Buffer.BlockCopy(tempArray, 0, powerSupport, 0, 2);
            }

            if (powerSupport[1] == 0x01)
            {
                // Check DCMI paramater revision 0x02 = DCMI errata for advanced
                // power management.  If the paramater version is 2, it should
                // support advanced power management.
                if (response.ParameterRevision == 0x02)
                {
                    // Get DCMI Capabilities for advanced power averages
                    response = (GetDcmiCapabilitiesResponse)this.IpmiSendReceive(
                        new GetDcmiCapabilitiesRequest(0x05), typeof(GetDcmiCapabilitiesResponse));

                    if (response.CompletionCode == 0)
                    {
                        // GetDcmiCapabilitiesResponse Response Data
                        byte[] capabilities = response.ResponseData;

                        // The number of supported rolling average time periods
                        int averages = (int)capabilities[0];

                        if (averages > 0)
                        {
                            // Loop through the available averages
                            for (int i = 0; i < averages; i++)
                            {
                                // Increment the Index Offset
                                index++;

                                //[7:6]: Time duration units 
                                //[5-0]: Time duration (Maximum of 63 units)
                                byte[] timeperiod = IpmiSharedFunc.ByteSplit(capabilities[index], new int[2] {
                                    6, 0
                                });

                                // Get Power Readings Array (DCMI spec)
                                // Reading mode: 0x01 = standard, 0x02 = advanced
                                PowerReadingSupport powerreadings = PowerReadingSupport(0x02, capabilities[index]);

                                // create a new instance of the power reading class
                                PowerReading pwr = new PowerReading(powerreadings.CompletionCode);

                                if (pwr.CompletionCode == 0)
                                {
                                    pwr.SetParamaters(powerreadings.Readings);

                                    // Units of time (number of units)
                                    pwr.TimeNumber = Convert.ToInt32(timeperiod[1]);

                                    // time sample (hours, minutes etc)
                                    pwr.TimeUnit = Convert.ToInt16(timeperiod[0]);
                                }
                                // add pwr to the return list
                                returnlist.Add(pwr);
                            }
                        }
                        else // get standard power statistics
                        {
                            return(GetPowerReading());
                        }
                    }
                    else
                    {
                        // create a new instance of the power reading class
                        PowerReading pwr = new PowerReading(response.CompletionCode);
                        // add ERROR pwr to the return list
                        returnlist.Add(pwr);
                    }
                }
                else // standard power statistics
                {
                    return(GetPowerReading());
                }
            }
            else
            {
                // power management is unsupported
                // create a new instance of the power reading class
                PowerReading pwr = new PowerReading(response.CompletionCode);

                // system does not support power readings
                pwr.PowerSupport = false;

                // add pwr to the return list
                returnlist.Add(pwr);
            }

            return(returnlist);
        }
        /// <summary>
        ///  Get Sensor Data Repository Information Incrementally. Returns SDR Info.
        /// </summary>
        public virtual SdrCollection GetSdrIncrement()
        {
            // Default Record Off Set
            int offSet = 0;

            // Number of Bytes to Read. 0xFF for entire record.
            int bytesToRead = 0;

            // SDR RecordId (0000h for entry point)
            ushort recordId = 0;

            // Last SDR RecordId (aborts event log Loop)
            ushort lastRecordId = 65535;

            // security mech to step out of loop.
            int pass = 0;

            // create sdr record collection for raw SDR records.
            IpmiSdrCollection records = new IpmiSdrCollection();

            // reserve the SDR for partial reads
            ReserveSdrResponse reserve = (ReserveSdrResponse)this.IpmiSendReceive(
                new ReserveSdrRequest(), typeof(ReserveSdrResponse));

            if (reserve.CompletionCode == 0)
            {
                // reserved LS byte
                byte reserveLs = reserve.ReservationLS;

                // reserved MS byte
                byte reserveMs = reserve.ReservationMS;

                // lenght of the SDR record
                int recordLenght = 0;

                // sdr record index
                int index = 0;

                // retrieve all records while connected by recursively calling the SDR entry command
                while (recordId != lastRecordId || pass > 1000)
                {
                    // create SDR record
                    SdrRecord sdr = new SdrRecord();
                    {
                        // initialize offset to zero for new record
                        offSet = 0;

                        // initialize to the minimum read size of 5 bytes. (extended to 14 on incremental read)
                        bytesToRead = 5;

                        // get the SEL record
                        GetSdrPartialResponse response = (GetSdrPartialResponse)this.IpmiSendReceive(
                            new GetSdrPartialRequest(reserveLs, reserveMs, recordId, offSet, bytesToRead), typeof(GetSdrPartialResponse));

                        // set the sdr completion code.
                        sdr.completionCode = response.CompletionCode;

                        if (response.CompletionCode == 0)
                        {
                            // set record id
                            sdr.RecordId = new byte[2] {
                                response.RecordData[1], response.RecordData[0]
                            };

                            // set the record version
                            sdr.RecordVersion = response.RecordData[2];

                            // set record type
                            sdr.RecordType = response.RecordData[3];

                            // set record lenght
                            sdr.RecordLenght = response.RecordData[4];

                            // convert record lenght to int & add the initial 5 bytes.
                            recordLenght = (Convert.ToInt32(response.RecordData[4])) + 5;

                            // create SDR byte array to hold record data.
                            byte[] sdrDataRecord = new byte[recordLenght];

                            // initilize sdr array index to zero
                            index = 0;

                            // copy SDR data to the sdr data record array and increase the index
                            Buffer.BlockCopy(response.RecordData, 0, sdrDataRecord, index, bytesToRead);
                            index += bytesToRead;

                            // increase the offset by bytes already read
                            offSet += bytesToRead;

                            int offsetPass = 0;

                            // recursively get partial sdr record until the offset reaches the recordlenght
                            while (offSet < recordLenght || offsetPass > 100)
                            {
                                // get maximum read chunk (14 bytes or less).
                                bytesToRead = (recordLenght - offSet);
                                // the size to 14 byte increments
                                bytesToRead = (bytesToRead > 14) ? 14 : bytesToRead;

                                // get partial SDR record
                                GetSdrPartialResponse partialResponse = (GetSdrPartialResponse)this.IpmiSendReceive(
                                    new GetSdrPartialRequest(reserve.ReservationLS, reserve.ReservationMS, recordId, offSet, bytesToRead), typeof(GetSdrPartialResponse));

                                if (partialResponse.CompletionCode == 0)
                                {
                                    // copy SDR data to the sdr data array and increase the index size by bytes read.
                                    Buffer.BlockCopy(partialResponse.RecordData, 0, sdrDataRecord, index, bytesToRead);
                                    index += bytesToRead;

                                    // increase the offset by the bytes read
                                    offSet += bytesToRead;
                                }
                                else
                                {
                                    // set the sdr completion code.
                                    sdr.completionCode = partialResponse.CompletionCode;
                                    break;
                                }

                                offsetPass++;
                            }

                            // set the record data to the fully populdated sdrDataRecord array
                            sdr.RecordData = sdrDataRecord;

                            // update the record Id (signals loop exit)
                            recordId = BitConverter.ToUInt16(new byte[2] {
                                response.RecordIdMsByte, response.RecordIdLsByte
                            }, 0);
                        }
                        else
                        {
                            break;
                        }
                    }

                    pass++;

                    // add the record to the collection
                    records.Add(sdr);
                }
            }

            // return collection
            SdrCollection sdrMessages = new SdrCollection();

            sdrMessages.completionCode = reserve.CompletionCode;

            if (reserve.CompletionCode != 0)
            {
                sdrMessages.command = typeof(ReserveSdrResponse).ToString();
            }

            // check response collection holds values
            if (records.Count > 0)
            {
                // sdr version array
                byte[] verarr = new byte[2];

                // record id
                short id;

                foreach (SdrRecord record in records)
                {
                    if (record.completionCode == 0)
                    {
                        // record Id
                        id = BitConverter.ToInt16(record.RecordId, 0);

                        // populdate version array
                        Buffer.BlockCopy(IpmiSharedFunc.ByteSplit(record.RecordVersion, new int[2] {
                            4, 0
                        }), 0, verarr, 0, 2);

                        string sVersion = Convert.ToUInt16(verarr[1]).ToString(CultureInfo.InvariantCulture) + "." + Convert.ToInt16(verarr[0]).ToString(CultureInfo.InvariantCulture);

                        // set version
                        Decimal version = 0;
                        // sdr record version number
                        if (!decimal.TryParse(sVersion, out version))
                        {
                            version = 0;
                        }

                        GetSdrMetatData(id, version, record.RecordType, record, ref sdrMessages);
                    }
                    else
                    {
                        sdrMessages.command       += " : " + sdrMessages.completionCode + ". RecordId:" + record.RecordId.ToString();
                        sdrMessages.completionCode = record.completionCode;
                    }
                }
            }

            return(sdrMessages);
        }
        /// <summary>
        /// Returns a byte array with all bytes from a specific area of the fru: Chassis, Baseboard, Product
        /// </summary>
        private byte[] ReadFruAreaBytes(int deviceId, ushort offset, bool maxLenght, out byte completionCode)
        {
            byte countToRead = 0x10;
            byte loOffset;
            byte hiOffset;

            List <byte> areaBytes = new List <byte>();

            IpmiSharedFunc.SplitWord(offset, out loOffset, out hiOffset);

            ushort            totalDataRead = countToRead;
            GetFruDataRequest fruRequest    =
                new GetFruDataRequest(loOffset, hiOffset, countToRead)
            {
                DeviceId = (byte)deviceId
            };

            GetFruDataResponse fruResponse = IpmiSendReceive <GetFruDataResponse>(fruRequest);

            completionCode = fruResponse.CompletionCode;

            if (completionCode == 0x00)
            {
                ushort dataSize = FruArea.AreaLength(fruResponse.DataReturned);
                totalDataRead = Math.Min(countToRead, dataSize);
                IpmiSharedFunc.AppendArrayToList(fruResponse.DataReturned, areaBytes, totalDataRead);
                offset += totalDataRead;
                int pass = 0;

                while (dataSize > totalDataRead || pass > 12)
                {
                    IpmiSharedFunc.SplitWord(offset, out loOffset, out hiOffset);

                    if (!maxLenght)
                    {
                        countToRead = (byte)Math.Min(countToRead, dataSize - totalDataRead);
                    }
                    else
                    {
                        countToRead = (byte)Math.Min(byte.MaxValue, dataSize - totalDataRead);
                    }

                    fruRequest = new GetFruDataRequest(loOffset, hiOffset, countToRead)
                    {
                        DeviceId = (byte)deviceId
                    };
                    // send request for more data
                    fruResponse    = IpmiSendReceive <GetFruDataResponse>(fruRequest);
                    totalDataRead += countToRead;
                    offset        += countToRead;

                    completionCode = fruResponse.CompletionCode;

                    if (completionCode == 0x00)
                    {
                        IpmiSharedFunc.AppendArrayToList(fruResponse.DataReturned, areaBytes, countToRead);
                    }
                    else
                    {
                        break;
                    }

                    pass++;
                }

                if (pass > 12)
                {
                    completionCode = 0xEF;
                }
            }

            return(areaBytes.ToArray());
        }
        /// <summary>
        ///  Get Sensor Data Repository. Returns SDR Info.
        /// </summary>
        public virtual SdrCollection GetSdr()
        {
            // Default Record Off Set
            int offSet = 0;

            // Number of Bytes to Read. 0xFF for entire record.
            byte bytesToRead = 0xFF;

            // SDR RecordId (0000h for entry point)
            ushort recordId = 0;

            // Last SDR RecordId (aborts event log Loop)
            ushort lastRecordId = 65535;

            // security mech to step out of loop.
            int pass = 0;

            // create sdr record collection for raw SDR records.
            IpmiSdrCollection records = new IpmiSdrCollection();

            // reserve the SDR for partial reads
            ReserveSdrResponse reserve = (ReserveSdrResponse)this.IpmiSendReceive(
                new ReserveSdrRequest(), typeof(ReserveSdrResponse));

            if (reserve.CompletionCode == 0)
            {
                // reserved LS byte
                byte reserveLs = reserve.ReservationLS;

                // reserved MS byte
                byte reserveMs = reserve.ReservationMS;

                // retrieve all records while connected by recursively calling the SDR entry command
                while (recordId != lastRecordId || pass > 1000)
                {
                    // create SDR record
                    SdrRecord sdr = new SdrRecord();
                    {
                        // get the SEL record
                        GetSdrPartialResponse response = (GetSdrPartialResponse)this.IpmiSendReceive(
                            new GetSdrPartialRequest(reserveLs, reserveMs, recordId, offSet, bytesToRead), typeof(GetSdrPartialResponse));

                        if (response.CompletionCode == 0)
                        {
                            sdr.completionCode = response.CompletionCode;

                            // set record id
                            sdr.RecordId = new byte[2] {
                                response.RecordData[1], response.RecordData[0]
                            };

                            // set the record version
                            sdr.RecordVersion = response.RecordData[2];

                            // set record type
                            sdr.RecordType = response.RecordData[3];

                            // set record lenght
                            sdr.RecordLenght = response.RecordData[4];

                            // set the record data to record data
                            sdr.RecordData = response.RecordData;

                            // update the record Id (signals loop exit)
                            recordId = BitConverter.ToUInt16(new byte[2] {
                                response.RecordIdMsByte, response.RecordIdLsByte
                            }, 0);
                        }
                        else
                        {
                            sdr.completionCode = response.CompletionCode;
                            break;
                        }
                    }

                    pass++;

                    // add the record to the collection
                    records.Add(sdr);
                }
            }

            // return collection
            SdrCollection sdrMessages = new SdrCollection();

            // check response collection holds values
            if (records.Count > 0)
            {
                // sdr version array
                byte[] verarr = new byte[2];

                // record id
                short id;

                foreach (SdrRecord record in records)
                {
                    if (record.completionCode == 0)
                    {
                        // set the sdr collection completion code to indicate a failure occurred
                        sdrMessages.completionCode = record.completionCode;

                        // record Id
                        id = BitConverter.ToInt16(record.RecordId, 0);

                        // populdate version array
                        Buffer.BlockCopy(IpmiSharedFunc.ByteSplit(record.RecordVersion, new int[2] {
                            4, 0
                        }), 0, verarr, 0, 2);

                        string sVersion = Convert.ToUInt16(verarr[1]).ToString(CultureInfo.InvariantCulture) + "." + Convert.ToInt16(verarr[0]).ToString(CultureInfo.InvariantCulture);

                        // set version
                        Decimal version = 0;
                        // sdr record version number
                        if (!decimal.TryParse(sVersion, out version))
                        {
                            version = 0;
                        }

                        GetSdrMetatData(id, version, record.RecordType, record, ref sdrMessages);
                    }
                    // set the sdr completion code to indicate a failure occurred
                    sdrMessages.completionCode = record.completionCode;
                }
            }

            return(sdrMessages);
        }
示例#17
0
        /// <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);
        }
示例#18
0
 internal SetSelTimeRequest(DateTime date)
 {
     offset = Convert.ToInt32(IpmiSharedFunc.SecondsFromUnixOffset(date));
 }
示例#19
0
        /// <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);
        }
示例#20
0
        /// <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);
        }