Package javax.bluetooth

Examples of javax.bluetooth.DataElement


            bluetooth = BluetoothStack.getBluetoothStack();
            SDPClientChannel sdpChannel = new SDPClientChannel(remoteDevice, null);
            bluetooth.connectL2CAPChannel(sdpChannel, remoteDevice, (short)0x0001);
            //TODO fill propper attrIDs this ignores the parameter and gets all available
            byte[] attributeList = { 0x35, 0x05, 0x0a, 0x00, 0x00, (byte)0xff, (byte)0xff };
            DataElement attributeListElement = new DataElement(attributeList);
            isPopulated = false;
            sdpChannel.send_SDP_ServiceAttributeRequest((short)0x00, (short)0xff, serviceRecordHandle, attributeListElement);
            int timeout = 0;
            while (!isPopulated) {
                try {
View Full Code Here


    /** @see javax.bluetooth.ServiceRecord#getConnectionURL(int, boolean) */
    public String getConnectionURL(int requiredSecurity, boolean mustBeMaster) {
        //"btspp://0050CD00321B:3;authenticate=true;encrypt=false;master=true", 
        if (remoteDevice == null) throw new IllegalArgumentException("Service Record is not propperly populted.");
        String url = "btl2cap://" + remoteDevice.getBluetoothAddress() + ":";
        DataElement protocolDescriptorListElement = (DataElement)attributes.get(new Integer(4));
        if (protocolDescriptorListElement == null)
            throw new IllegalArgumentException("Service Record is not propperly populated. Protocol Descriptor is missing.");
        Enumeration protocolDescriptorList = (Enumeration)protocolDescriptorListElement.getValue();
        while (protocolDescriptorList.hasMoreElements()) {
            DataElement protocolDescriptorElement = (DataElement)protocolDescriptorList.nextElement();
            if (protocolDescriptorElement == null)
                throw new IllegalArgumentException("Service Record is not propperly populated. Protocol Descriptor is missing.");
            Enumeration protocolParameterList = (Enumeration)protocolDescriptorElement.getValue();
            if (protocolParameterList.hasMoreElements()) {
                DataElement protocolDescriptor = (DataElement)protocolParameterList.nextElement();
                if (protocolDescriptor != null) {
                    if (protocolDescriptor.getDataType() == DataElement.UUID) {
                        UUID protocolDescriptorUUID = (UUID)protocolDescriptor.getValue();
                        if (protocolDescriptorUUID.toLong() == 0x0100) //is L2CAP
                        {
                            if (protocolParameterList.hasMoreElements()) {
                                DataElement protocolPSMElement = (DataElement)protocolParameterList.nextElement();
                                {
                                    if (protocolPSMElement != null) {
                                        if (protocolPSMElement.getDataType() == DataElement.UUID) {
                                            UUID psm = (UUID)protocolPSMElement.getValue();
                                            url += psm.toString() + ";";
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        else //is not L2CAP
                        {
                            url += protocolDescriptorUUID.toString() + ";";
                            while (protocolParameterList.hasMoreElements()) {
                                DataElement parameter = (DataElement)protocolParameterList.nextElement();
                                url += parameter.toString() + ";";
                            }
                            break;
                        }
                    }
                }
View Full Code Here

    /** @param dataPacket */
    private void receive_SDP_ServiceSearchRequest(byte[] dataPacket) {
        Debug.println(4, "SDP: Received Service Search Request:", dataPacket);
        short transactionID              = (short)(((short)dataPacket[1] & 0xff) << 8 | ((short)dataPacket[2] & 0xff));
        DataElement serviceSearchPattern = new DataElement(dataPacket, 5);
        Vector handels                   = sdpServer.getServiceRecordHandels(serviceSearchPattern);
        short resultHandlesCount         = 0;
        if (handels != null) resultHandlesCount = (short)handels.size();
        short sdpLenght = (short)(5 + (resultHandlesCount * 4));
        byte[] serviceSearchResponse = new byte[10 + (resultHandlesCount * 4)];
 
View Full Code Here

        Debug.println(4, "SDP: Received Service Attibute Request:", dataPacket);
        short transactionID = (short)(((short)dataPacket[1] & 0xff) << 8 | ((short)dataPacket[2] & 0xff));
        long serviceRecordHandle = (long)(((long)dataPacket[5] & 0xff) | ((long)dataPacket[6] & 0xff) << 8 |
            ((long)dataPacket[7] & 0xff) << 16 | ((long)dataPacket[8] & 0xff) << 24);
        short maximumAttributeCount = (short)(((short)dataPacket[9] & 0xff) | ((short)dataPacket[10] & 0xff) << 8);
        DataElement attributeIDList = new DataElement(dataPacket, 11);
        byte[] attributeList        = sdpServer.getAttributes(serviceRecordHandle, attributeIDList);

        /*byte[] attributeList = {0x35, 0x59,
        0x09, 0x00, 0x00, 0x0a,0x00, 0x00, 0x01, 0x00,
        0x09, 0x00, 0x01, 0x35, 0x05, 0x1a, 0x00, 0x00, 0x11, 0x01,
View Full Code Here

    public Vector getServiceRecordHandels(DataElement serviceSearchPattern) {
        Vector serviceRecordHandles = new Vector();
        Enumeration elements = (Enumeration)serviceSearchPattern.getValue();
        while (elements.hasMoreElements()) {
            DataElement element = (DataElement)elements.nextElement();
            UUID uuid = (UUID)element.getValue();
            System.out.println("getSRH for " + uuid);
            serviceRecordHandles = (Vector)uuidMap.get(uuid);
            break;
            //TODO this only takes the first UUID into consideration and not all like it's supposed to...
        }
View Full Code Here

            Long psmKey = new Long(serviceUUIDshort);
            if (services.contains(psmKey)) { //return false; 
            }
            services.put(psmKey, channelFactory);
            Long serviceHandle = new Long(serviceHandleCounter++);
            DataElement serviceRecordElement = new DataElement(DataElement.DATSEQ);
            serviceRecordElement.addElement(new DataElement(DataElement.U_INT_2, 0));
            serviceRecordElement.addElement(new DataElement(DataElement.U_INT_4, serviceHandle.longValue()));
            DataElement recordElements = new DataElement(serviceRecord);
            Enumeration elements = (Enumeration)recordElements.getValue();
            while (elements.hasMoreElements()) {
                DataElement element = (DataElement)elements.nextElement();
                serviceRecordElement.addElement(element);
            }
            serviceRecords.put(serviceHandle, serviceRecordElement.toByteArray());
            UUID serviceUUID = new UUID(serviceUUIDshort);
            Vector serviceHandleVector = (Vector)uuidMap.get(serviceUUID);
View Full Code Here

        Debug.println(4, "SDP: Received Service Attibute Response:", dataPacket);
        if (remoteDevice != null) {
            short transactionID = (short)(((short)dataPacket[1] & 0xff) << 8 | ((short)dataPacket[2] & 0xff));
            //short attributeListByteCount = (short)(((short) dataPacket[5] & 0xff) << 8 | ((short) dataPacket[6]& 0xff));
            SDPRemoteServiceRecord serviceRecord = null;
            DataElement attributeList = new DataElement(dataPacket, 7);
            //System.out.println("AttributeList : "+attributeList);
            Enumeration attributeElements = (Enumeration)attributeList.getValue();
            while (attributeElements.hasMoreElements()) {
                DataElement attrIDElement    = (DataElement)attributeElements.nextElement();
                DataElement attrValueElement = (DataElement)attributeElements.nextElement();
                int attrID                   = (int)attrIDElement.getLong();
                if (attrID == 0) {
                    serviceRecord = (SDPRemoteServiceRecord)
                        remoteDevice.serviceRecords.get(new Integer((int)attrValueElement.getLong()));
                }
                if (serviceRecord != null) serviceRecord.setAttributeValue(attrID, attrValueElement);
            }
            if (serviceRecord != null) serviceRecord.isPopulated = true;
        }
View Full Code Here

    private void receive_SDP_ServiceSearchAttributeResponse(byte[] dataPacket) {
        Debug.println(4, "SDP: Received Service Attibute Response:", dataPacket);
        if ((remoteDevice != null)) {
            short transactionID                   = (short)(((short)dataPacket[1] & 0xff) << 8 | ((short)dataPacket[2] & 0xff));
            DataElement serviceAttributeListElement = new DataElement(dataPacket, 7);
            Enumeration serviceAttributeList      = (Enumeration)serviceAttributeListElement.getValue();
            while (serviceAttributeList.hasMoreElements()) {
                DataElement attributeList            = (DataElement)serviceAttributeList.nextElement();
                SDPRemoteServiceRecord serviceRecord = null;
                Enumeration attributeElements        = (Enumeration)attributeList.getValue();
                while (attributeElements.hasMoreElements()) {
                    DataElement attrIDElement    = (DataElement)attributeElements.nextElement();
                    DataElement attrValueElement = (DataElement)attributeElements.nextElement();
                    int attrID                   = (int)attrIDElement.getLong();
                    if (attrID == 0) {
                        serviceRecord = (SDPRemoteServiceRecord)
                            remoteDevice.serviceRecords.get(new Integer((int)attrValueElement.getLong()));
                        if (serviceRecord == null)
                            serviceRecord = new SDPRemoteServiceRecord(remoteDevice, (int)attrValueElement.getLong());
                    }
                    if (serviceRecord != null) { serviceRecord.setAttributeValue(attrID, attrValueElement); }
                }
                if (serviceRecord != null) {
                    serviceRecord.isPopulated = true;
View Full Code Here

public class SDPLocalServiceRecord implements ServiceRecord {
    public Hashtable attributes;

    public SDPLocalServiceRecord(short serviceClassID) {
        this.attributes = new Hashtable();
        DataElement serviceClassIDList = new DataElement(DataElement.DATSEQ);
        UUID serviceClassUUID = new UUID(serviceClassID);
        serviceClassIDList.addElement(new DataElement(DataElement.UUID, new UUID(0x1111)));
        attributes.put(new Integer(1), serviceClassIDList);
        DataElement protocolDescriptorList = new DataElement(DataElement.DATSEQ);
        DataElement l2capDescriptor = new DataElement(DataElement.DATSEQ);
        l2capDescriptor.addElement(new DataElement(DataElement.UUID, new UUID(0x0100)));
        protocolDescriptorList.addElement(l2capDescriptor);
        DataElement rfcommDescriptor = new DataElement(DataElement.DATSEQ);
        rfcommDescriptor.addElement(new DataElement(DataElement.UUID, new UUID(0x0003)));
        rfcommDescriptor.addElement(new DataElement(DataElement.U_INT_1, 1));
        protocolDescriptorList.addElement(rfcommDescriptor);
        attributes.put(new Integer(4), protocolDescriptorList);
        DataElement browseClassIDList = new DataElement(DataElement.DATSEQ);
        UUID browseClassUUID = new UUID(0x1002);
        browseClassIDList.addElement(new DataElement(DataElement.UUID, browseClassUUID));
        attributes.put(new Integer(5), browseClassIDList);
        DataElement languageBaseAttributeIDList = new DataElement(DataElement.DATSEQ);
        languageBaseAttributeIDList.addElement(new DataElement(DataElement.U_INT_2, 25966));
        languageBaseAttributeIDList.addElement(new DataElement(DataElement.U_INT_2, 106));
        languageBaseAttributeIDList.addElement(new DataElement(DataElement.U_INT_2, 256));
        attributes.put(new Integer(6), languageBaseAttributeIDList);
        DataElement profileDescriptorList = new DataElement(DataElement.DATSEQ);
        DataElement profileDescriptor = new DataElement(DataElement.DATSEQ);
        profileDescriptor.addElement(new DataElement(DataElement.UUID, new UUID(0x1111)));
        profileDescriptor.addElement(new DataElement(DataElement.U_INT_2, 256));
        profileDescriptorList.addElement(profileDescriptor);
        attributes.put(new Integer(9), profileDescriptorList);
        attributes.put(new Integer(256), new DataElement(DataElement.STRING, "Tini Service"));
    }
View Full Code Here

        catch (BluetoothStateException e) {
            e.printStackTrace();
            return null;
        }
        String url = "btl2cap://" + localDev.getBluetoothAddress() + ":";
        DataElement protocolDescriptorListElement = (DataElement)attributes.get(new Integer(4));
        if (protocolDescriptorListElement == null)
            throw new IllegalArgumentException("Service Record is not propperly populated. Protocol Descriptor is missing.");
        Enumeration protocolDescriptorList = (Enumeration)protocolDescriptorListElement.getValue();
        while (protocolDescriptorList.hasMoreElements()) {
            DataElement protocolDescriptorElement = (DataElement)protocolDescriptorList.nextElement();
            if (protocolDescriptorElement == null)
                throw new IllegalArgumentException("Service Record is not propperly populated. Protocol Descriptor is missing.");
            Enumeration protocolParameterList = (Enumeration)protocolDescriptorElement.getValue();
            if (protocolParameterList.hasMoreElements()) {
                DataElement protocolDescriptor = (DataElement)protocolParameterList.nextElement();
                if (protocolDescriptor != null) {
                    if (protocolDescriptor.getDataType() == DataElement.UUID) {
                        UUID protocolDescriptorUUID = (UUID)protocolDescriptor.getValue();
                        if (protocolDescriptorUUID.toLong() == 0x0100) //is L2CAP
                        {
                            if (protocolParameterList.hasMoreElements()) {
                                DataElement protocolPSMElement = (DataElement)protocolParameterList.nextElement();
                                {
                                    if (protocolPSMElement != null) {
                                        if (protocolPSMElement.getDataType() == DataElement.UUID) {
                                            UUID psm = (UUID)protocolPSMElement.getValue();
                                            url += psm.toString() + ";";
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        else //is not L2CAP
                        {
                            url += protocolDescriptorUUID.toString() + ";";
                            while (protocolParameterList.hasMoreElements()) {
                                DataElement parameter = (DataElement)protocolParameterList.nextElement();
                                url += parameter.toString() + ";";
                            }
                            break;
                        }
                    }
                }
View Full Code Here

TOP

Related Classes of javax.bluetooth.DataElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.