/// <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);
        }
コード例 #2
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);
        }