com.dalsemi.tininet
Class TININet

java.lang.Object
  |
  +--com.dalsemi.tininet.TININet

public class TININet
extends Object

This class is used to set up parameters for TINI networking.


Field Summary
static int COMMITTED
          Network configuration is committed to flash memory.
static int ETH_STATUS_LINK
          Ethernet controller status flags.
static int ETH_STATUS_RX
           
static int ETH_STATUS_TX
           
static int RESTORE_DISABLED
          Network configuration restore is disabled.
static int UNCOMMITTED
          Network configuration is not committed to flash memory.
 
Constructor Summary
TININet()
           
 
Method Summary
static void addInterfaceEntry(byte[] name, byte[] ipAddr, byte[] subnet, byte[] gateway, byte flags, byte type, int transmitter)
          Adds an interface to the network interface list with the given parameters.
static void commitNetworkState()
          Commits the current network configuration to flash.
static byte[] createIPFromString(String fromThis)
          Creates an array that stores the IP address represented by the String argument.
static String createIPString(byte[] fromThis)
          Creates a standard IP String from the given byte array.
static void disableNetworkRestore()
          Disables the ability to commit or restore network configuration until the bank 7 application is re-flashed.
static byte[] getARPCacheTable()
          Gets the current ARP cache table.
static byte[] getConnectionTable()
          Gets the current connection table.
static String getDHCPServerIP()
          Gets the IP address of DHCP server.
static void getDHCPServerIP(byte[] address)
          Gets the IP address of the DHCP server.
static int getDNSTimeout()
          Gets the timeout value for DNS queries.
static String getDomainname()
          Gets the domain name of TINI.
static String getEthernetAddress()
          Gets the ethernet MAC address in dotted decimal notation.
static void getEthernetAddress(byte[] address)
          Gets the ethernet MAC address into the given byte array, with the most significant byte first.
static int getEthernetStatus()
          Returns status from the Ethernet controller.
static String getGatewayIP()
          Gets the gateway IP address of the default interface as a String.
static void getGatewayIP(byte[] address)
          Gets the gateway IP address of the default interface.
static String getGatewayIP(String interfaceName)
          Gets the IP address of the gateway for the specified interface as a string in dotted decimal notation.
static void getGatewayIP(String interfaceName, byte[] address)
          Gets the IP address of the gateway for the specified interface.
static String getHostname()
          Gets the hostname of TINI.
static boolean getInterfaceInfo(int interfaceNum, byte[] data)
          Gets interface information for given interface and stores it in byte array.
static String getIPAddress()
          Gets the IP address of the default interface as a String.
static void getIPAddress(byte[] address)
          Gets the IP address of the default interface.
static String getIPAddress(String interfaceName)
          Gets the IP address of the specified interface as a String.
static void getIPAddress(String interfaceName, byte[] address)
          Gets the IP address of the specified interface.
static String getMailhost()
          Gets the IP address of the default mailhost.
static int getNetworkCommitState()
          Returns the commit state as UNCOMMITED, COMMITTED or RESTORE_DISABLED
static String getPrimaryDNS()
          Gets the primary DNS server address.
static int getProxyPort()
          Gets the proxy server port number.
static String getProxyServer()
          Gets the IP address of the proxy server.
static String getSecondaryDNS()
          Gets the secondary DNS server address.
static String getSubnetMask()
          Gets the subnet mask of the default interface as a String.
static void getSubnetMask(byte[] address)
          Gets the subnet mask of the default interface.
static String getSubnetMask(String interfaceName)
          Gets the subnet mask of the specified interface as a String.
static void getSubnetMask(String interfaceName, byte[] address)
          Gets the subnet mask of the specified interface.
static void removeInterfaceEntry(byte[] name)
          Removes specified interface from the network interface list.
static boolean setDefaultInterface(byte[] name)
          Sets the default network interface.
static boolean setDHCPServerIP(String dhcpServer)
          Sets the IP address of the DHCP server to the given string.
static boolean setDNSTimeout(int dnsTimeout)
          Sets the DNS timeout in milliseconds.
static boolean setDomainname(String domain)
          Sets the domain name to the given string.
static boolean setGatewayIP(byte[] gateway)
          Sets the gateway address for the default interface.
static boolean setGatewayIP(String gateway)
          Sets the gateway IP for the default interface.
static boolean setGatewayIP(String interfaceName, byte[] gateway)
          Sets the gateway IP address for the specified interface.
static boolean setGatewayIP(String interfaceName, String gateway)
          Sets the gateway IP for the specified interface.
static boolean setHostname(String host)
          Sets the host name to the given string.
static boolean setIPAddress(byte[] localIP)
          Sets the IP address of the default interface.
static boolean setIPAddress(String localIP)
          Sets the IP address of the default interface.
static boolean setIPAddress(String interfaceName, byte[] localIP)
          Sets the IP address of the specified interface.
static boolean setIPAddress(String interfaceName, String localIP)
          Sets the IP address of the specified interface.
static boolean setMailhost(String mailhost)
          Sets the mail host to the given IP address.
static boolean setOptions(byte[] dhcp, byte[] ip, byte[] gateway, byte[] subnet, byte[] dns1, byte[] dns2, byte[] domain, byte[] mailhost)
          Sets multiple network configuration settings.
static boolean setPrimaryDNS(String primaryDNS)
          Sets the primary DNS IP address to the given string.
static boolean setProxyPort(int proxyPort)
          Sets the proxy port.
static boolean setProxyServer(String proxyServer)
          Sets the proxy server IP address
static boolean setSecondaryDNS(String secondDNS)
          Sets the secondary DNS IP address to the given string.
static boolean setSubnetMask(byte[] subnetMask)
          Sets the subnet mask of the default interface.
static boolean setSubnetMask(String subnetMask)
          Sets the subnet mask of the default interface.
static boolean setSubnetMask(String interfaceName, byte[] subnetMask)
          Sets the subnet mask of the specified interface.
static boolean setSubnetMask(String interfaceName, String subnetMask)
          Sets the subnet mask of the specified interface.
static void update()
          Forces a reload of network settings from the configuration file /etc/.tininet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNCOMMITTED

public static final int UNCOMMITTED
Network configuration is not committed to flash memory.

COMMITTED

public static final int COMMITTED
Network configuration is committed to flash memory.

RESTORE_DISABLED

public static final int RESTORE_DISABLED
Network configuration restore is disabled.

ETH_STATUS_LINK

public static final int ETH_STATUS_LINK
Ethernet controller status flags.

ETH_STATUS_TX

public static final int ETH_STATUS_TX

ETH_STATUS_RX

public static final int ETH_STATUS_RX
Constructor Detail

TININet

public TININet()
Method Detail

update

public static void update()
Forces a reload of network settings from the configuration file /etc/.tininet

createIPString

public static String createIPString(byte[] fromThis)
Creates a standard IP String from the given byte array. The first four bytes are written as unsigned decimal digits, separated by periods. For instance, if the input array consists of all 0's, the returned String would be "0.0.0.0".
Parameters:
fromThis - byte array with the IP address to convert to a String
Returns:
representation of the IP address
See Also:
createIPFromString(String)

createIPFromString

public static byte[] createIPFromString(String fromThis)
Creates an array that stores the IP address represented by the String argument. If fromThis is "180.0.16.52", then the bytes in the array returned by this method are 180, 0, 16, and 52, starting at offset 0 of the returned array.
Parameters:
fromThis - String reporesentation of the IP address
Returns:
array representation of the IP address
See Also:
createIPString(byte[])

getHostname

public static String getHostname()
Gets the hostname of TINI.
Returns:
TINI hostname

getDomainname

public static String getDomainname()
Gets the domain name of TINI.
Returns:
TINI domain name

getPrimaryDNS

public static String getPrimaryDNS()
Gets the primary DNS server address.
Returns:
primary DNS server address, if the address has not been set an empty string is returned

getSecondaryDNS

public static String getSecondaryDNS()
Gets the secondary DNS server address.
Returns:
secondary DNS server address, if the address has not been set an empty string is returned

getMailhost

public static String getMailhost()
Gets the IP address of the default mailhost.
Returns:
IP address of the default mailhost, if the address has not been set an empty string is returned

getDNSTimeout

public static int getDNSTimeout()
Gets the timeout value for DNS queries.
Returns:
timeout in milliseconds

getDHCPServerIP

public static void getDHCPServerIP(byte[] address)
Gets the IP address of the DHCP server.
Parameters:
address - byte array of length four to be filled with the IP DHCP server address, most significant byte of address is stored at index zero

getDHCPServerIP

public static String getDHCPServerIP()
Gets the IP address of DHCP server.
Returns:
IP address of the dhcp server in dotted decimal notation, if the address has not been set an empty string is returned

getIPAddress

public static void getIPAddress(String interfaceName,
                                byte[] address)
Gets the IP address of the specified interface. Currently loopback (lo), ethernet (eth0) and ppp are currently supported.
Parameters:
interfaceName - network interface (lo, eth0 or pppn)
address - byte array of length four to be filled in with the IP address, most significant byte of address is stored at index zero

getIPAddress

public static String getIPAddress(String interfaceName)
Gets the IP address of the specified interface as a String. Currently loopback (lo), ethernet (eth) and ppp are supported
Parameters:
interfaceName - network interface (lo, eth or ppp)
Returns:
the IP address of the named interface, if the address has not been set an empty string is returned

getIPAddress

public static String getIPAddress()
Gets the IP address of the default interface as a String.
Returns:
the IP address in dotted decimal notation, if the address has not been set an empty string is returned

getIPAddress

public static void getIPAddress(byte[] address)
Gets the IP address of the default interface.
Parameters:
address - byte array of length four to be filled with the IP address, most significant byte of address is stored at index zero

getGatewayIP

public static void getGatewayIP(byte[] address)
Gets the gateway IP address of the default interface.
Parameters:
address - byte array of length four to be filled with the IP address, most significant byte of address is stored at index zero

getGatewayIP

public static String getGatewayIP()
Gets the gateway IP address of the default interface as a String.
Returns:
ip address of the gateway in dotted decimal notation, if the address has not been set an empty string is returned

getGatewayIP

public static void getGatewayIP(String interfaceName,
                                byte[] address)
Gets the IP address of the gateway for the specified interface.
Parameters:
interfaceName - network interface (lo, eth or ppp)
address - byte array of length four to be filled with the IP address, most significant byte of address is stored at index zero

getGatewayIP

public static String getGatewayIP(String interfaceName)
Gets the IP address of the gateway for the specified interface as a string in dotted decimal notation.
Returns:
IP address of the gateway in dotted decimal notation, if the address has not been set an empty string is returned

getSubnetMask

public static void getSubnetMask(byte[] address)
Gets the subnet mask of the default interface.
Parameters:
address - byte array of length four to be filled with the subnet mask, most significant byte of mask is stored at index zero

getSubnetMask

public static String getSubnetMask()
Gets the subnet mask of the default interface as a String.
Returns:
the subnet mask in dotted decimal notation, if the address has not been set an empty string is returned

getSubnetMask

public static void getSubnetMask(String interfaceName,
                                 byte[] address)
Gets the subnet mask of the specified interface.
Parameters:
interfaceName - network interface (lo, eth or ppp)
address - byte array of length four to be filled with the subnet mask, most significant byte of mask is stored at index zero

getSubnetMask

public static String getSubnetMask(String interfaceName)
Gets the subnet mask of the specified interface as a String.
Returns:
the subnet mask in dotted decimal notation, if the address has not been set an empty string is returned

getEthernetAddress

public static void getEthernetAddress(byte[] address)
Gets the ethernet MAC address into the given byte array, with the most significant byte first.
Parameters:
address - byte array of length six to be filled with the ethernet address

getEthernetAddress

public static String getEthernetAddress()
Gets the ethernet MAC address in dotted decimal notation.
Returns:
the ethernet address in dotted decimal notation, if the address has not been set an empty string is returned

getProxyServer

public static String getProxyServer()
Gets the IP address of the proxy server.
Returns:
the IP address of the proxy server in dotted decimal notation, if the address has not been set an empty string is returned

getProxyPort

public static int getProxyPort()
Gets the proxy server port number.
Returns:
the proxy port number

setHostname

public static boolean setHostname(String host)
Sets the host name to the given string.
Parameters:
host - hostname
Returns:
true if successful

setDomainname

public static boolean setDomainname(String domain)
Sets the domain name to the given string.
Parameters:
domain - domain name to be set
Returns:
true if successful

setPrimaryDNS

public static boolean setPrimaryDNS(String primaryDNS)
Sets the primary DNS IP address to the given string.
Parameters:
primaryDNS - primary DNS IP address in dotted decimal notation
Returns:
true if successful

setSecondaryDNS

public static boolean setSecondaryDNS(String secondDNS)
Sets the secondary DNS IP address to the given string.
Parameters:
secondDNS - secondary DNS IP address in dotted decimal notation
Returns:
true if successful

setMailhost

public static boolean setMailhost(String mailhost)
Sets the mail host to the given IP address.
Parameters:
mailhost - IP address of the mail host in dotted decimal notation
Returns:
true on success

setDNSTimeout

public static boolean setDNSTimeout(int dnsTimeout)
Sets the DNS timeout in milliseconds. If the timeout value is set to zero, a fallback and retry procedure will take effect. The DNS client will retry starting at 2 seconds and doubling until reaching 16 seconds. The DNS resolver will try four times in this period to resolve the name. * 2s * 4s * 8s * 16s
Parameters:
dnsTimeout - timeout value in milliseconds, zero for fallback and retry
Returns:
true on success

setDHCPServerIP

public static boolean setDHCPServerIP(String dhcpServer)
Sets the IP address of the DHCP server to the given string.
Parameters:
dhcpServer - DHCP server IP address in dotted decimal notation
Returns:
true on success

setIPAddress

public static boolean setIPAddress(byte[] localIP)
Sets the IP address of the default interface.
Parameters:
localIP - IP address, MSB of address is index zero
Returns:
true on success

setIPAddress

public static boolean setIPAddress(String localIP)
Sets the IP address of the default interface.
Parameters:
localIP - IP address in dotted decimal notation
Returns:
true on success

setIPAddress

public static boolean setIPAddress(String interfaceName,
                                   byte[] localIP)
Sets the IP address of the specified interface.
Parameters:
interfaceName - network interface name
localIP - IP address, MSB of address is index zero
Returns:
true on success

setIPAddress

public static boolean setIPAddress(String interfaceName,
                                   String localIP)
Sets the IP address of the specified interface.
Parameters:
interfaceName - network interface name
localIP - IP address in dotted decimal notation
Returns:
true on success

setGatewayIP

public static boolean setGatewayIP(byte[] gateway)
Sets the gateway address for the default interface.
Parameters:
gateway - IP address of the gateway, MSB of address is index zero
Returns:
true on success

setGatewayIP

public static boolean setGatewayIP(String gateway)
Sets the gateway IP for the default interface.
Parameters:
gateway - IP address of the gateway in dotted decimal notation
Returns:
true on success

setGatewayIP

public static boolean setGatewayIP(String interfaceName,
                                   byte[] gateway)
Sets the gateway IP address for the specified interface.
Parameters:
interfaceName - network interface name
gateway - ip address of the gateway, MSB of address is index zero
Returns:
true on success

setGatewayIP

public static boolean setGatewayIP(String interfaceName,
                                   String gateway)
Sets the gateway IP for the specified interface.
Parameters:
interfaceName - network interface name
gateway - IP address of the gateway in dotted decimal notation
Returns:
true on success

setSubnetMask

public static boolean setSubnetMask(byte[] subnetMask)
Sets the subnet mask of the default interface.
Parameters:
subnetMask - subnet mask, MSB of mask is at index zero
Returns:
true on success

setSubnetMask

public static boolean setSubnetMask(String subnetMask)
Sets the subnet mask of the default interface.
Parameters:
subnetMask - subnet mask in dotted decimal notation
Returns:
true on success

setSubnetMask

public static boolean setSubnetMask(String interfaceName,
                                    byte[] subnetMask)
Sets the subnet mask of the specified interface.
Parameters:
interfaceName - network interface name
subnetMask - subnet mask, MSB of mask is at index zero
Returns:
true on success

setSubnetMask

public static boolean setSubnetMask(String interfaceName,
                                    String subnetMask)
Sets the subnet mask of the specified interface.
Parameters:
interfaceName - network interface name
subnetMask - subnet mask in dotted decimal notation
Returns:
true on success

setProxyServer

public static boolean setProxyServer(String proxyServer)
Sets the proxy server IP address
Parameters:
proxyServer - IP address of the proxy server, MSB of address is at index zero
Returns:
true on success

setProxyPort

public static boolean setProxyPort(int proxyPort)
Sets the proxy port.
Parameters:
proxyPort - the port number to be used for proxy
Returns:
true on success

setOptions

public static boolean setOptions(byte[] dhcp,
                                 byte[] ip,
                                 byte[] gateway,
                                 byte[] subnet,
                                 byte[] dns1,
                                 byte[] dns2,
                                 byte[] domain,
                                 byte[] mailhost)
Sets multiple network configuration settings.
Parameters:
dhcp - IP address of the DHCP server, MSB of address is at index zero
ip - IP address of the local machine, MSB of address is at index zero
gateway - IP address of gateway address, MSB of address is at index zero
subnet - subnet mask, MSB of address is at index zero
dns1 - IP address of the primary DNS server, MSB of address is at index zero
dns2 - IP address of the secondary DNS server, MSB of address is at index zero
domain - domain name stored as a byte array
mailhost - IP address of the outgoing mail server, MSB of address is at index zero
Returns:
true on success

getConnectionTable

public static byte[] getConnectionTable()
Gets the current connection table.
Returns:
byte array containing the connection table

getARPCacheTable

public static byte[] getARPCacheTable()
Gets the current ARP cache table.
Returns:
byte array containing the ARP cache table

commitNetworkState

public static void commitNetworkState()
                               throws CommitException
Commits the current network configuration to flash.
Note: Committing the network settings to flash allows applications to use TINIOS.blastHeapOnReboot(BLAST_ALL) to clear the heap to a virgin state on reboot without having to reconfigure the network through a serial connection. If the settings are committed, TINIOS will compare the settings stored in flash to those stored in heap at boot time. If they are different, the settings in flash will be copied over those in the heap. This allows TINIOS to always boot up with a known network configuration. Due to the nature of flash (write once and erase) the network settings can only be committed one time using the CommitNetworkState method. Once they are committed you can disable boot time restore using the disableNetworkRestore. Effectively this is the same as if the network configuration was never committed. The configuration is stored in RAM only and can be reconfigured at will. The network configuration can only be recommitted after erasing (zapping) bank 7 which will also erase the bank 7 application. The easiest way to do this is to simply reload the bank 7 application using JavaKit. This functionality is available in a login session using the slush commands "ipconfig -C" and "ipconfig -D".
Throws:
CommitException - if state has already been committed.
See Also:
getNetworkCommitState, disableNetworkRestore, com.dalsemi.system.TINIOS.getBootState

getNetworkCommitState

public static int getNetworkCommitState()
Returns the commit state as UNCOMMITED, COMMITTED or RESTORE_DISABLED
Returns:
the current commit state
See Also:
CommitNetworkState, disableNetworkRestore, com.dalsemi.system.TINIOS.getBootState

disableNetworkRestore

public static void disableNetworkRestore()
Disables the ability to commit or restore network configuration until the bank 7 application is re-flashed.
See Also:
CommitNetworkState, getNetworkCommitState, com.dalsemi.system.TINIOS.getBootState

setDefaultInterface

public static boolean setDefaultInterface(byte[] name)
Sets the default network interface.
Parameters:
name - network interface, lo (loopback), eth (ethernet) or ppp
Returns:
true if inteface was successfully set as the default

getInterfaceInfo

public static boolean getInterfaceInfo(int interfaceNum,
                                       byte[] data)
Gets interface information for given interface and stores it in byte array. Returns true if information was found using supplied interface number.
Parameters:
interfaceNum - network interface number
data - buffer for interface info
Returns:
true if interface info was found

addInterfaceEntry

public static void addInterfaceEntry(byte[] name,
                                     byte[] ipAddr,
                                     byte[] subnet,
                                     byte[] gateway,
                                     byte flags,
                                     byte type,
                                     int transmitter)
Adds an interface to the network interface list with the given parameters.
Parameters:
name - network interface lo(loopback), eth(ethernet) or ppp
ipAddr - IP address of the new interface
subnet - subnet mask of the new interface
gateway - gateway IP address of the new interface
flags - network configuration flags mapped as follows:
      flags.0 = used - should always be set
      flags.1 = active - should be set if the interface is to be active
      flags.2 = default - set if this should be the default network interface
      flags.3 = UNUSED - must be cleared
      flags.4 = routable - set if interface is to carry routable packets
      flags.5 = multicasting enabled - set if interface supports multicast
      flags.6 = UNUSED - must be cleared
type - type of network interface ethernet = 1, ppp = 2, loopback = 3
transmitter - 24 bit transmitter routine address represented as a 32-bit int

removeInterfaceEntry

public static void removeInterfaceEntry(byte[] name)
Removes specified interface from the network interface list.
Parameters:
name - network interface name to remove

getEthernetStatus

public static int getEthernetStatus()
Returns status from the Ethernet controller. The status includes Link Transmit Receive
Parameters:
name - network interface name to remove
Returns:
The bitwise-or of any of the ETH_STATUS_XXX integer constants