// Path: src/net/propero/rdp/crypto/CryptoException.java
// public class CryptoException extends Exception {
// 	private static final long serialVersionUID = -5302220269148556116L;
// 
// 	public CryptoException() {
// 		super();
// 	}
// 
// 	/**
// 	 * @param reason
// 	 *            the reason why the exception was thrown.
// 	 */
// 	public CryptoException(String reason) {
// 		super(reason);
// 	}
// }


import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import net.propero.rdp.crypto.CryptoException;
import org.apache.log4j.Logger;
import java.io.BufferedInputStream;

/* ISO.java
 * Component: ProperJavaRDP
 * 
 * Revision: $Revision: 12 $
 * Author: $Author: miha_vitorovic $
 * Date: $Date: 2007-05-11 13:49:09 +0200 (Fri, 11 May 2007) $
 *
 * Copyright (c) 2005 Propero Limited
 *
 * Purpose: ISO layer of communication
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 * 
 * (See gpl.txt for details of the GNU General Public License.)
 * 
 */
package net.propero.rdp;




public abstract class ISO {
	static Logger logger = Logger.getLogger(ISO.class);

	private HexDump dump = null;

	protected Socket rdpsock = null;

	private DataInputStream in = null;

	private DataOutputStream out = null;

	/* this for the ISO Layer */
	private static final int CONNECTION_REQUEST = 0xE0;

	private static final int CONNECTION_CONFIRM = 0xD0;

	private static final int DISCONNECT_REQUEST = 0x80;

	private static final int DATA_TRANSFER = 0xF0;

	private static final int ERROR = 0x70;

	private static final int PROTOCOL_VERSION = 0x03;

	private static final int EOT = 0x80;

	/**
	 * Construct ISO object, initialises hex dump
	 */
	public ISO() {
		dump = new HexDump();
	}

	/**
	 * Initialise an ISO PDU
	 * 
	 * @param length
	 *            Desired length of PDU
	 * @return Packet configured as ISO PDU, ready to write at higher level
	 */
	public RdpPacket_Localised init(int length) {
		RdpPacket_Localised data = new RdpPacket_Localised(length + 7);// getMemory(length+7);
		data.incrementPosition(7);
		data.setStart(data.getPosition());
		return data;
	}

	/*
	 * protected Socket negotiateSSL(Socket sock) throws Exception{ return sock; }
	 */

	/**
	 * Create a socket for this ISO object
	 * 
	 * @param host
	 *            Address of server
	 * @param port
	 *            Port on which to connect socket
	 * @throws IOException
	 */
	protected void doSocketConnect(InetAddress host, int port)
			throws IOException {
		this.rdpsock = new Socket(host, port);
	}

	/**
	 * Connect to a server
	 * 
	 * @param host
	 *            Address of server
	 * @param port
	 *            Port to connect to on server
	 * @throws IOException
	 * @throws RdesktopException
	 * @throws OrderException
	 * @throws CryptoException
	 */
	public void connect(InetAddress host, int port) throws IOException,

// Path: src/net/propero/rdp/crypto/CryptoException.java
// public class CryptoException extends Exception {
// 	private static final long serialVersionUID = -5302220269148556116L;
// 
// 	public CryptoException() {
// 		super();
// 	}
// 
// 	/**
// 	 * @param reason
// 	 *            the reason why the exception was thrown.
// 	 */
// 	public CryptoException(String reason) {
// 		super(reason);
// 	}
// }


// Path: src/net/propero/rdp/ISO.java
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import net.propero.rdp.crypto.CryptoException;
import org.apache.log4j.Logger;
import java.io.BufferedInputStream;

/* ISO.java
 * Component: ProperJavaRDP
 * 
 * Revision: $Revision: 12 $
 * Author: $Author: miha_vitorovic $
 * Date: $Date: 2007-05-11 13:49:09 +0200 (Fri, 11 May 2007) $
 *
 * Copyright (c) 2005 Propero Limited
 *
 * Purpose: ISO layer of communication
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 * 
 * (See gpl.txt for details of the GNU General Public License.)
 * 
 */
package net.propero.rdp;




public abstract class ISO {
	static Logger logger = Logger.getLogger(ISO.class);

	private HexDump dump = null;

	protected Socket rdpsock = null;

	private DataInputStream in = null;

	private DataOutputStream out = null;

	/* this for the ISO Layer */
	private static final int CONNECTION_REQUEST = 0xE0;

	private static final int CONNECTION_CONFIRM = 0xD0;

	private static final int DISCONNECT_REQUEST = 0x80;

	private static final int DATA_TRANSFER = 0xF0;

	private static final int ERROR = 0x70;

	private static final int PROTOCOL_VERSION = 0x03;

	private static final int EOT = 0x80;

	/**
	 * Construct ISO object, initialises hex dump
	 */
	public ISO() {
		dump = new HexDump();
	}

	/**
	 * Initialise an ISO PDU
	 * 
	 * @param length
	 *            Desired length of PDU
	 * @return Packet configured as ISO PDU, ready to write at higher level
	 */
	public RdpPacket_Localised init(int length) {
		RdpPacket_Localised data = new RdpPacket_Localised(length + 7);// getMemory(length+7);
		data.incrementPosition(7);
		data.setStart(data.getPosition());
		return data;
	}

	/*
	 * protected Socket negotiateSSL(Socket sock) throws Exception{ return sock; }
	 */

	/**
	 * Create a socket for this ISO object
	 * 
	 * @param host
	 *            Address of server
	 * @param port
	 *            Port on which to connect socket
	 * @throws IOException
	 */
	protected void doSocketConnect(InetAddress host, int port)
			throws IOException {
		this.rdpsock = new Socket(host, port);
	}

	/**
	 * Connect to a server
	 * 
	 * @param host
	 *            Address of server
	 * @param port
	 *            Port to connect to on server
	 * @throws IOException
	 * @throws RdesktopException
	 * @throws OrderException
	 * @throws CryptoException
	 */
	public void connect(InetAddress host, int port) throws IOException,

			RdesktopException, OrderException, CryptoException {
