01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26: package com.sun.kvem.jsr082.bluetooth;
27:
28: import java.io.IOException;
29: import javax.bluetooth.UUID;
30: import javax.microedition.io.Connector;
31: import javax.microedition.io.Connection;
32: import com.sun.midp.security.SecurityToken;
33: import com.sun.midp.security.ImplicitlyTrustedClass;
34: import com.sun.midp.io.j2me.btl2cap.Protocol;
35: import com.sun.midp.io.BluetoothUrl;
36: import com.sun.midp.jsr082.SecurityInitializer;
37:
38: /**
39: * Contains common Servive Discovery Protocol data.
40: */
41: public class SDP {
42:
43: /**
44: * Inner class to request security token from SecurityInitializer.
45: * SecurityInitializer should be able to check this inner class name.
46: */
47: static private class SecurityTrusted implements
48: ImplicitlyTrustedClass {
49: };
50:
51: /** Internal security token that grants access to restricted API. */
52: private static SecurityToken internalSecurityToken = SecurityInitializer
53: .requestToken(new SecurityTrusted());
54:
55: /** Special object used by SDP to authenticate internal URL's. */
56: private static Object systemToken = new Object();
57:
58: /** SDP UUID. */
59: public static final String UUID = new UUID(0x0001).toString();
60:
61: /** SDP server PSM. This value is defined by Bluetooth specification */
62: public static final int PSM = 0x0001;
63:
64: /**
65: * Creates and opens btl2cap connection for using by SDP.
66: *
67: * @param name btl2cap connection URL without protocol name
68: * @return required connection instance, that is
69: * <code>L2CAPConnection</code> for client or
70: * <code>L2CAPConnectionNotifier</code> for server
71: * @exception IOException if connection fails
72: */
73: static Connection getL2CAPConnection(String name)
74: throws IOException {
75: BluetoothUrl url = new BluetoothUrl(BluetoothUrl.L2CAP, name,
76: systemToken);
77: Protocol l2cap = new Protocol();
78: return l2cap.openPrim(internalSecurityToken, url,
79: Connector.READ_WRITE);
80: }
81:
82: /**
83: * Checks that given token is an internal one. Used to authenticate
84: * an URL as generated by SDP.
85: * @param token token to check
86: * @return <code>true</code> if the object given is exactly the internal
87: * system token, <code>false</code> otherwise
88: */
89: public static boolean checkSystemToken(Object token) {
90: return token == systemToken;
91: }
92: }
|