FileDocCategorySizeDatePackage
Protocol.javaAPI DocphoneME MR2 API (J2ME)6060Wed May 02 18:00:30 BST 2007com.sun.midp.io.j2me.btl2cap

Protocol

public class Protocol extends com.sun.midp.io.BluetoothProtocol
Provides "btl2cap" protocol implementation

Fields Summary
static final int
MAX_STACK_MTU
Keeps maximum MTU supported by the BT stack.
Constructors Summary
public Protocol()
Constructs an instance.

        int maxReceiveMTU;
        try {
            maxReceiveMTU = Integer.parseInt(System.getProperty(
                    "bluetooth.l2cap.receiveMTU.max"));
        } catch (NumberFormatException e) {
            maxReceiveMTU = L2CAPConnection.DEFAULT_MTU;
        }        
        MAX_STACK_MTU = maxReceiveMTU;
    
        super(BluetoothUrl.L2CAP);
    
Methods Summary
protected voidcheckUrl(com.sun.midp.io.BluetoothUrl url)
Ensures URL parameters have valid values. Sets receiveMTU if undefined.

param
url URL to check
exception
IllegalArgumentException if invalid url parameters found
exception
BluetoothConnectionException if url parameters are not acceptable due to Bluetooth stack limitations

        
        if (url.receiveMTU == -1) {
            url.receiveMTU = L2CAPConnection.DEFAULT_MTU;
        }
        
        if (url.isSystem()) {
            return;
        }
        
        super.checkUrl(url);
        
        if (!url.isServer && (url.port <= 0x1000 || url.port >= 0xffff ||
                    ((url.port & 1) != 1) || ((url.port & 0x100) != 0))) {
            throw new IllegalArgumentException("Invalid PSM: " + url.port);
        }
            
        // IMPL_NOTE BluetoothConnectionException should be thrown here
        // It is temporary substituted by IllegalArgumentException 
        // to pass TCK succesfully. To be changed back when fixed
        // TCK arrives. The erroneous TCK test is 
        // javasoft.sqe.tests.api.javax.bluetooth.Connector.L2Cap.
        //                             openClientTests.L2Cap1014()
        //
        // Correct code here is
        // throw new BluetoothConnectionException(
        //    BluetoothConnectionException.UNACCEPTABLE_PARAMS,
        //    <message>);
        if (url.receiveMTU < L2CAPConnection.MINIMUM_MTU) {
            throw new IllegalArgumentException(
                "Receive MTU is too small");
        }
        
        if (url.receiveMTU > MAX_STACK_MTU) {
            throw new IllegalArgumentException("Receive MTU is too large");
        }
        
        if (url.transmitMTU != -1 && url.transmitMTU > MAX_STACK_MTU) {
            throw new BluetoothConnectionException(
                BluetoothConnectionException.UNACCEPTABLE_PARAMS,
                "Transmit MTU is too large");
        }
    
protected javax.microedition.io.ConnectionclientConnection(com.sun.midp.security.SecurityToken token, int mode)
Ensures that permissions are proper and creates client side connection.

param
token security token if passed by caller, or null
param
mode I/O access mode
return
proper L2CAPConnectionImpl instance
exception
IOException if openning connection fails.

        checkForPermission(token, Permissions.BLUETOOTH_CLIENT);
        return new L2CAPConnectionImpl(url, mode);
    
public javax.microedition.io.ConnectionopenPrim(java.lang.Object token, com.sun.midp.io.BluetoothUrl url, int mode)
Cheks permissions and opens requested connection.

param
token security token passed by calling class
param
url BluetoothUrl instance that defines required connection stringname the URL without protocol name and colon
param
mode Connector.READ_WRITE or Connector.READ or Connector.WRITE
return
a notifier in case of server connection string, open connection in case of client one.
exception
IOException if opening connection fails.

        return openPrimImpl(token, url, mode);
    
protected javax.microedition.io.ConnectionserverConnection(com.sun.midp.security.SecurityToken token, int mode)
Ensures that permissions are proper and creates required notifier at server side.

param
token security token if passed by caller, or null
param
mode I/O access mode
return
proper L2CAPNotifierImpl instance
exception
IOException if openning connection fails

        checkForPermission(token, Permissions.BLUETOOTH_SERVER);
        return new L2CAPNotifierImpl(url, mode);