/*
*
*
* Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version
* 2 only, as published by the Free Software Foundation.
*
* 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 version 2 for more details (a copy is
* included at /legal/license.txt).
*
* You should have received a copy of the GNU General Public License
* version 2 along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 or visit www.sun.com if you need additional
* information or have any questions.
*/
package com.sun.kvem.jsr082.bluetooth;
import java.io.IOException;
import javax.bluetooth.UUID;
import javax.microedition.io.Connector;
import javax.microedition.io.Connection;
import com.sun.midp.security.SecurityToken;
import com.sun.midp.security.ImplicitlyTrustedClass;
import com.sun.midp.io.j2me.btl2cap.Protocol;
import com.sun.midp.io.BluetoothUrl;
import com.sun.midp.jsr082.SecurityInitializer;
/**
* Contains common Servive Discovery Protocol data.
*/
public class SDP {
/**
* Inner class to request security token from SecurityInitializer.
* SecurityInitializer should be able to check this inner class name.
*/
static private class SecurityTrusted
implements ImplicitlyTrustedClass {};
/** Internal security token that grants access to restricted API. */
private static SecurityToken internalSecurityToken =
SecurityInitializer.requestToken(new SecurityTrusted());
/** Special object used by SDP to authenticate internal URL's. */
private static Object systemToken = new Object();
/** SDP UUID. */
public static final String UUID = new UUID(0x0001).toString();
/** SDP server PSM. This value is defined by Bluetooth specification */
public static final int PSM = 0x0001;
/**
* Creates and opens btl2cap connection for using by SDP.
*
* @param name btl2cap connection URL without protocol name
* @return required connection instance, that is
* <code>L2CAPConnection</code> for client or
* <code>L2CAPConnectionNotifier</code> for server
* @exception IOException if connection fails
*/
static Connection getL2CAPConnection(String name) throws IOException {
BluetoothUrl url = new BluetoothUrl(BluetoothUrl.L2CAP, name, systemToken);
Protocol l2cap = new Protocol();
return l2cap.openPrim(internalSecurityToken, url, Connector.READ_WRITE);
}
/**
* Checks that given token is an internal one. Used to authenticate
* an URL as generated by SDP.
* @param token token to check
* @return <code>true</code> if the object given is exactly the internal
* system token, <code>false</code> otherwise
*/
public static boolean checkSystemToken(Object token) {
return token == systemToken;
}
}
|