예제 #1
0
 /// <summary>
 /// Simple command ping-pong.  The TCP interface acknowledges simple command
 /// completion with a UINT32=0;
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="cmd"></param>
 private void SendCmdAndGetAck(NetworkStream stream, TcpTpmCommands cmd)
 {
     if (stream == null)
     {
         return;
     }
     WriteInt(stream, (int)cmd);
     GetAck(stream, cmd.ToString());
 }
예제 #2
0
        private void SendVarArrayCmdAndGetAck(NetworkStream stream, TcpTpmCommands cmd, byte[] buf)
        {
            var b = new ByteBuf();

            b.Append(Globs.HostToNet((int)cmd));
            b.Append(Globs.HostToNet(buf.Length));
            b.Append(buf);
            Write(stream, b.GetBuffer());

            GetAck(stream, cmd.ToString());
        }
예제 #3
0
        /// <summary>
        /// This function serves command event streams.
        /// </summary>
        /// <param name="s"></param>
        void ServePlatform(NetworkStream inStream, NetworkStream outStream)
        {
            while (true)
            {
                int            command    = ReadInt(inStream);
                TcpTpmCommands theCommand = (TcpTpmCommands)command;
                //Console.WriteLine("platform " + theCommand.ToString());
                switch (theCommand)
                {
                case TcpTpmCommands.SignalPowerOn:
                case TcpTpmCommands.SignalPowerOff:
                case TcpTpmCommands.SignalPPOn:
                case TcpTpmCommands.SignalPPOff:
                case TcpTpmCommands.SignalCancelOn:
                case TcpTpmCommands.SignalCancelOff:
                case TcpTpmCommands.SignalNvOn:
                case TcpTpmCommands.SignalNvOff:
                case TcpTpmCommands.SignalKeyCacheOn:
                case TcpTpmCommands.SignalKeyCacheOff:
                    //case TcpTpmCommands.InjectEps:
                    if (TheDeviceType == DeviceType.Tcp)
                    {
                        WriteInt((int)theCommand, outStream);
                        GetAndSendAck(outStream, inStream);
                    }
                    else
                    {
                        NotImplemented(theCommand);
                        Write(ZeroInt, inStream);
                    }
                    break;

                case TcpTpmCommands.SessionEnd:
                case TcpTpmCommands.Stop:
                    if (TheDeviceType == DeviceType.Tcp)
                    {
                        // Forward session end request and do not wait for ACK
                        WriteInt((int)theCommand, outStream);
                        //GetAndSendAck(outStream, inStream);
                    }
                    // Send back ACK and exit the communication loop
                    Write(ZeroInt, inStream);
                    return;

                default:
                    throw new Exception("bad message");
                }
            }
        }
예제 #4
0
 void NotImplemented(TcpTpmCommands command)
 {
     Console.ForegroundColor = ConsoleColor.Red;
     Console.WriteLine("Command not implemented:" + command.ToString());
     Console.ResetColor();
 }
예제 #5
0
        /// <summary>
        /// This function serves command event streams.
        /// </summary>
        /// <param name="s"></param>
        void ServeCommand(NetworkStream inStream, NetworkStream outStream)
        {
            while (true)
            {
                int            command    = ReadInt(inStream);
                TcpTpmCommands theCommand = (TcpTpmCommands)command;
                //Console.WriteLine("command " + theCommand.ToString());
                if (theCommand == TcpTpmCommands.RemoteHandshake)
                {
                    int clientVersion = ReadInt(inStream);
                    if (clientVersion == 0)
                    {
                        throw new Exception("Incompatible client (version 0, expected version 1 or higher)");
                    }
                }
                if (TheDeviceType == DeviceType.Tcp)
                {
                    WriteInt((int)theCommand, outStream);
                    switch (theCommand)
                    {
                    case TcpTpmCommands.SignalHashStart:
                    case TcpTpmCommands.SignalHashEnd:
                        break;

                    case TcpTpmCommands.SendCommand:
                        byte[]          loc    = Read(1, inStream);
                        byte[]          cmd    = ReadVarArray(inStream);
                        CommandModifier active = new CommandModifier();
                        Write(loc, outStream);
                        WriteVarArray(cmd, outStream);

                        WriteVarArray(ReadVarArray(outStream), inStream);
                        break;

                    case TcpTpmCommands.SignalHashData:
                        byte[] data = ReadVarArray(inStream);
                        WriteVarArray(data, outStream);
                        break;

                    case TcpTpmCommands.RemoteHandshake:
                        WriteInt(Version, outStream);
                        int endPointVersion = ReadInt(outStream);
                        if (endPointVersion == 0)
                        {
                            throw new Exception("Incompatible end point (version 0, expected version 1 or higher)");
                        }
                        tpmEndPointInfo = ReadInt(outStream);
                        WriteInt(Version, inStream);
                        WriteInt(tpmEndPointInfo, inStream);
                        break;

                    case TcpTpmCommands.SessionEnd:
                    case TcpTpmCommands.Stop:
                        if (TheDeviceType == DeviceType.Tcp)
                        {
                            // Forward session end request and do not wait for ACK
                            WriteInt((int)theCommand, outStream);
                            //GetAndSendAck(outStream, inStream);
                        }
                        // Send back ACK and exit the communication loop
                        Write(ZeroInt, inStream);
                        return;

                    default:
                        throw new NotImplementedException("");
                    }
                    GetAndSendAck(outStream, inStream);
                }
                else // TBS device
                {
                    switch (theCommand)
                    {
                    case TcpTpmCommands.SignalHashStart:
                    case TcpTpmCommands.SignalHashEnd:
                        NotImplemented(theCommand);
                        Write(OneInt, inStream);
                        break;

                    case TcpTpmCommands.SignalHashData:
                        byte[] data = ReadVarArray(inStream);
                        NotImplemented(theCommand);
                        Write(OneInt, inStream);
                        break;

                    case TcpTpmCommands.SendCommand:
                        byte[]          loc    = Read(1, inStream);
                        byte[]          cmd    = ReadVarArray(inStream);
                        CommandModifier active = new CommandModifier();
                        byte[]          outBuf;

                        tbsDevice.DispatchCommand(active, cmd, out outBuf);

                        WriteVarArray(outBuf, inStream);
                        Write(ZeroInt, inStream);
                        break;

                    case TcpTpmCommands.RemoteHandshake:
                        WriteInt(Version, inStream);
                        WriteInt(tpmEndPointInfo, inStream);
                        Write(ZeroInt, inStream);
                        break;

                    case TcpTpmCommands.SessionEnd:
                    case TcpTpmCommands.Stop:
                        // Send back ACK and exit the communication loop
                        Write(ZeroInt, inStream);
                        return;

                    default:
                        throw new NotImplementedException("");
                    }
                }
            }
        }