Ejemplo n.º 1
0
        public void NoSvcClass()
        {
            // Rfcomm/None
            ServiceRecordBuilder bldr = new ServiceRecordBuilder();

            DoTestFails(bldr);
        }
Ejemplo n.º 2
0
        private void DoTest(string expectedDump, ServiceRecordBuilder bldr)
        {
            ServiceRecord rcd  = bldr.ServiceRecord;
            String        dump = ServiceRecordUtilities.Dump(rcd);

            Assert.AreEqual(expectedDump, dump);
        }
Ejemplo n.º 3
0
        private void DoTestFailsBuilderOrLater(ServiceRecordBuilder bldr)
        {
            ServiceRecord rcd = bldr.ServiceRecord;

            byte[] raw = new ServiceRecordCreator().CreateServiceRecord(rcd);
            Assert.Fail("Should have thrown2!");
        }
Ejemplo n.º 4
0
        public void BadProtoTypeWierd()
        {
            ServiceRecordBuilder bldr = new ServiceRecordBuilder();

            bldr.AddServiceClass(0x1101);
            bldr.ProtocolType = (BluetoothProtocolDescriptorType)9999;
            DoTestFails(bldr);
        }
        public void GeopOne()
        {
            String url = "btgoep://localhost:12AF51A9030C4B2937407F8C9ECB238A";
            ServiceRecordBuilder bldr   = ServiceRecordBuilder.FromJsr82ServerUri(url);
            ServiceRecord        record = bldr.ServiceRecord;
            String dump = ServiceRecordUtilities.Dump(record);

            Assert.AreEqual(ServiceRecordBuilderTests_Data.FooGoepOne, dump);
        }
Ejemplo n.º 6
0
        public void Four()
        {
            // None/Svc16
            ServiceRecordBuilder bldr = new ServiceRecordBuilder();

            bldr.AddServiceClass(-1);
            bldr.ProtocolType = BluetoothProtocolDescriptorType.None;
            DoTest(ServiceRecordBuilderTests_Data.Four, bldr);
        }
        public void L2capTwoWithName()
        {
            String url = "btl2cap://localhost:12af51a9030c4b2937407f8c9ecb238a;name=Aserv";
            ServiceRecordBuilder bldr   = ServiceRecordBuilder.FromJsr82ServerUri(url);
            ServiceRecord        record = bldr.ServiceRecord;
            String dump = ServiceRecordUtilities.Dump(record);

            Assert.AreEqual(ServiceRecordBuilderTests_Data.FooL2CapTwoWithName, dump);
        }
        public void One()
        {
            String url = "btspp://localhost:0000110100001000800000805F9B34FB";
            ServiceRecordBuilder bldr   = ServiceRecordBuilder.FromJsr82ServerUri(url);
            ServiceRecord        record = bldr.ServiceRecord;
            String dump = ServiceRecordUtilities.Dump(record);

            Assert.AreEqual(ServiceRecordBuilderTests_Data.One, dump);
        }
        public void L2capOne()
        {
            String url = "btl2cap://localhost:3B9FA89520078C303355AAA694238F08";
            ServiceRecordBuilder bldr   = ServiceRecordBuilder.FromJsr82ServerUri(url);
            ServiceRecord        record = bldr.ServiceRecord;
            String dump = ServiceRecordUtilities.Dump(record);

            Assert.AreEqual(ServiceRecordBuilderTests_Data.FooL2CapOne, dump);
        }
        public void RfcommOneNameSurrounded()
        {
            String url = "btspp://localhost:102030405060708090A1B1C1D1D1E100;auth=false;name=SPPEx;encrypt=false";
            ServiceRecordBuilder bldr   = ServiceRecordBuilder.FromJsr82ServerUri(url);
            ServiceRecord        record = bldr.ServiceRecord;
            String dump = ServiceRecordUtilities.Dump(record);

            Assert.AreEqual(ServiceRecordBuilderTests_Data.FooRfcommOne, dump);
        }
Ejemplo n.º 11
0
        public void One()
        {
            // Rfcomm/StdSvcClass
            ServiceRecordBuilder bldr = new ServiceRecordBuilder();

            bldr.AddServiceClass(BluetoothService.SerialPort);
            DoTest(ServiceRecordBuilderTests_Data.One, bldr);
            Assert.AreEqual(BluetoothProtocolDescriptorType.Rfcomm, bldr.ProtocolType);
        }
Ejemplo n.º 12
0
        public void CustomDuplicateBuiltIn()
        {
            // Note: not checking here WHEN the exception is thrown...
            ServiceRecordBuilder bldr = new ServiceRecordBuilder();

            bldr.AddServiceClass(0x1101);
            bldr.AddCustomAttributes(new ServiceAttribute(UniversalAttributeId.ServiceClassIdList,
                                                          new ServiceElement(ElementType.TextString, "DUMMY")));
            DoTestFailsBuilderOrLater(bldr);
        }
Ejemplo n.º 13
0
        public void OnePlusName()
        {
            // Rfcomm/StdSvcClass/SvcName
            ServiceRecordBuilder bldr = new ServiceRecordBuilder();

            bldr.AddServiceClass(BluetoothService.SerialPort);
            bldr.ServiceName = "Hello World!";
            DoTest(ServiceRecordBuilderTests_Data.OnePlusName, bldr);
            Assert.AreEqual("Hello World!", bldr.ServiceName);
        }
        public void FancyNameFollowed()
        {
            String url = "btspp://localhost:102030405060708090A1B1C1D1D1E100"
                         + ";name=aa-bb_cc dd1234;encrypt=false";
            ServiceRecordBuilder bldr   = ServiceRecordBuilder.FromJsr82ServerUri(url);
            ServiceRecord        record = bldr.ServiceRecord;
            String dump = ServiceRecordUtilities.Dump(record);

            Assert.AreEqual(ServiceRecordBuilderTests_Data.FooRfcommOneWithFancyName, dump);
        }
Ejemplo n.º 15
0
    static void chaosaSrb2()
    {
        ushort               u   = 0x37; // the mobile can get the number of  '10' using this
        ServiceElement       se  = new ServiceElement(ElementType.Int32, 10);
        ServiceAttribute     sa  = new ServiceAttribute(u, se);
        ServiceRecordBuilder srb = new ServiceRecordBuilder();

        srb.AddCustomAttribute(sa);
        ServiceRecord rcd = srb.ServiceRecord;
    }
Ejemplo n.º 16
0
        //TODO move to base class.  Maybe also make 'virtual' AddSimpleServiceRecord method.
        static ServiceRecord CreateSimpleServiceRecord(Guid serviceClass, string serviceName)
        {
            ServiceRecordBuilder bldr = new ServiceRecordBuilder();

            bldr.AddServiceClass(serviceClass);
            bldr.ServiceName = serviceName;
            var simpleSR = bldr.ServiceRecord;

            return(simpleSR);
        }
Ejemplo n.º 17
0
        public void Five_HSP_AG()
        {
            // HeadsetAG == Rfcomm/2xStdSvcClass/BtPDL
            ServiceRecordBuilder bldr = new ServiceRecordBuilder();

            bldr.AddServiceClass(BluetoothService.HeadsetAudioGateway);
            bldr.AddServiceClass(BluetoothService.GenericAudio);
            bldr.AddBluetoothProfileDescriptor(BluetoothService.Headset, 1, 0);
            DoTest(ServiceRecordBuilderTests_Data.Five_HSPv1_1_AG, bldr);
            Assert.AreEqual(BluetoothProtocolDescriptorType.Rfcomm, bldr.ProtocolType);
        }
Ejemplo n.º 18
0
        private ServiceRecord NewServiceRecord(Guid serviceId)
        {
            ServiceRecordBuilder recordBuilder = new ServiceRecordBuilder();

            recordBuilder.AddServiceClass(serviceId);
            recordBuilder.ProtocolType       = BluetoothProtocolDescriptorType.Rfcomm;
            recordBuilder.ProviderName       = "MobileAuthentication Inc.";
            recordBuilder.ServiceDescription = "Keep your computer safe from ilegal access. Lock and Unlock it without pressing a single key.";
            recordBuilder.ServiceName        = "BP-Authenticator";
            return(recordBuilder.ServiceRecord);
        }
        /// <inheritdoc />
        internal override void StartListening(EndPoint desiredLocalListenEndPoint, bool useRandomPortFailOver)
        {
            if (IsListening) throw new InvalidOperationException("Attempted to call StartListening when already listening.");
            if(!(desiredLocalListenEndPoint is BluetoothEndPoint)) throw new ArgumentException("Bluetooth connections can only be made from a local BluetoothEndPoint", "desiredLocalListenIPEndPoint");

            try
            {
                ServiceRecordBuilder bldr = new ServiceRecordBuilder();
                bldr.AddServiceClass((desiredLocalListenEndPoint as BluetoothEndPoint).Service);
                if (IsDiscoverable)
                    bldr.AddCustomAttribute(new ServiceAttribute(NetworkCommsBTAttributeId.NetworkCommsEndPoint, ServiceElement.CreateNumericalServiceElement(ElementType.UInt8, 1)));

                listenerInstance = new BluetoothListener(desiredLocalListenEndPoint as BluetoothEndPoint, bldr.ServiceRecord);

                listenerInstance.Start();
                listenerInstance.BeginAcceptBluetoothClient(BluetoothConnectionReceivedAsync, null);
            }
            catch (SocketException)
            {
                //If the port we wanted is not available
                if (useRandomPortFailOver)
                {
                    try
                    {
                        Guid service = Guid.NewGuid();

                        ServiceRecordBuilder bldr = new ServiceRecordBuilder();
                        bldr.AddServiceClass(service);
                        if (IsDiscoverable)
                            bldr.AddCustomAttribute(new ServiceAttribute(NetworkCommsBTAttributeId.NetworkCommsEndPoint, ServiceElement.CreateNumericalServiceElement(ElementType.UInt8, 1)));

                        listenerInstance = new BluetoothListener(new BluetoothEndPoint((desiredLocalListenEndPoint as BluetoothEndPoint).Address, service), bldr.ServiceRecord);
                        listenerInstance.Start();
                        listenerInstance.BeginAcceptBluetoothClient(BluetoothConnectionReceivedAsync, null);
                    }
                    catch (SocketException)
                    {
                        //If we get another socket exception this appears to be a bad IP. We will just ignore this IP
                        if (NetworkComms.LoggingEnabled) NetworkComms.Logger.Error("It was not possible to open a random port on " + desiredLocalListenEndPoint + ". This endPoint may not support listening or possibly try again using a different port.");
                        throw new CommsSetupShutdownException("It was not possible to open a random port on " + desiredLocalListenEndPoint + ". This endPoint may not support listening or possibly try again using a different port.");
                    }
                }
                else
                {
                    if (NetworkComms.LoggingEnabled) NetworkComms.Logger.Error("It was not possible to listen on " + desiredLocalListenEndPoint.ToString() + ". This endPoint may not support listening or possibly try again using a different port.");
                    throw new CommsSetupShutdownException("It was not possible to listen on " + desiredLocalListenEndPoint.ToString() + ". This endPoint may not support listening or possibly try again using a different port.");
                }
            }

            this.LocalListenEndPoint = desiredLocalListenEndPoint;

            this.IsListening = true;
        }
Ejemplo n.º 20
0
    static ServiceRecord Documentation_SRB_Simple_()
    {
        ServiceRecordBuilder bldr = new ServiceRecordBuilder();

        bldr.AddServiceClass(BluetoothService.SerialPort);
        bldr.ServiceName = "Alan's SPP service";
        bldr.AddCustomAttribute(new ServiceAttribute(0x8001,
                                                     ServiceElement.CreateNumericalServiceElement(ElementType.UInt16, 0xFEDC)));
        //
        ServiceRecord record = bldr.ServiceRecord;

        return(record);
    }
Ejemplo n.º 21
0
        public void CustomListBadItemType()
        {
            ServiceRecordBuilder bldr = new ServiceRecordBuilder();

            System.Collections.ArrayList list
                = new System.Collections.ArrayList();
            list.Add(33333);
            try {
                bldr.AddCustomAttributes(list);
                Assert.Fail("should have thrown!");
            } catch (ArgumentException) {
            }
        }
Ejemplo n.º 22
0
        public void Five_HSPv1_2()
        {
            // Headset == Rfcomm/2xStdSvcClass/BtPDL/1xCustom
            ServiceRecordBuilder bldr = new ServiceRecordBuilder();

            bldr.AddServiceClass(BluetoothService.HeadsetHeadset);
            bldr.AddServiceClass(BluetoothService.GenericAudio);
            bldr.AddBluetoothProfileDescriptor(BluetoothService.Headset, 1, 2);
            bldr.AddCustomAttribute(new ServiceAttribute(
                                        HeadsetProfileAttributeId.RemoteAudioVolumeControl,
                                        new ServiceElement(ElementType.Boolean, false)));
            DoTest(ServiceRecordBuilderTests_Data.Five_HSPv1_2_HS, bldr);
            Assert.AreEqual(BluetoothProtocolDescriptorType.Rfcomm, bldr.ProtocolType);
        }
Ejemplo n.º 23
0
        public void CustomOne()
        {
            // Rfcomm/StdSvcClass/SvcName
            ServiceRecordBuilder bldr = new ServiceRecordBuilder();

            bldr.AddServiceClass(BluetoothService.SerialPort);
            bldr.ServiceName = "Hello World!";
            ServiceAttribute attr = new ServiceAttribute(
                UniversalAttributeId.ServiceAvailability,
                ServiceElement.CreateNumericalServiceElement(ElementType.UInt8, 255));

            bldr.AddCustomAttribute(attr);
            DoTest(ServiceRecordBuilderTests_Data.OnePlusNamePlusCustomOne, bldr);
        }
Ejemplo n.º 24
0
        public void Three()
        {
            // Geop/StdSvcClass/PrvName/SvcDescr
            ServiceRecordBuilder bldr = new ServiceRecordBuilder();

            bldr.AddServiceClass(BluetoothService.ObexObjectPush);
            bldr.ProtocolType       = BluetoothProtocolDescriptorType.GeneralObex;
            bldr.ProviderName       = "Alan enterprises inc.";
            bldr.ServiceDescription = "\u2020 daggers to you";
            DoTest(ServiceRecordBuilderTests_Data.Three, bldr);
            Assert.AreEqual(BluetoothProtocolDescriptorType.GeneralObex, bldr.ProtocolType);
            Assert.AreEqual("Alan enterprises inc.", bldr.ProviderName);
            Assert.AreEqual("\u2020 daggers to you", bldr.ServiceDescription);
        }
Ejemplo n.º 25
0
        public void Two()
        {
            // Rfcomm/AllSvcClassTypesForms
            ServiceRecordBuilder bldr = new ServiceRecordBuilder();

            bldr.AddServiceClass(BluetoothService.SerialPort);
            bldr.AddServiceClass(new Guid("{00112233-4455-6677-8899-aabbccddeeff}"));
            bldr.AddServiceClass((UInt16)0x1106);
            bldr.AddServiceClass(0x7654);
            bldr.AddServiceClass(0x9901);
            bldr.AddServiceClass(0x123456);
            bldr.AddServiceClass(0x98761234);
            DoTest(ServiceRecordBuilderTests_Data.Two, bldr);
        }
Ejemplo n.º 26
0
        protected override void AddSimpleServiceRecord(out ServiceRecord fullServiceRecord,
                                                       int livePort, Guid serviceClass, string serviceName)
        {
            var livePortB = checked ((byte)livePort);

            m_sdpService = SdpService.CreateRfcomm(
                serviceClass,
                serviceName, livePortB, m_factory);
            ServiceRecordBuilder bldrDummy = new ServiceRecordBuilder();

            bldrDummy.AddServiceClass(serviceClass);
            bldrDummy.ServiceName = serviceName;
            fullServiceRecord     = bldrDummy.ServiceRecord;
            ServiceRecordHelper.SetRfcommChannelNumber(fullServiceRecord,
                                                       livePortB);
        }
Ejemplo n.º 27
0
        public void CustomTwoParamArray()
        {
            // Rfcomm/StdSvcClass/SvcName
            ServiceRecordBuilder bldr = new ServiceRecordBuilder();

            bldr.AddServiceClass(BluetoothService.SerialPort);
            bldr.ServiceName = "Hello World!";
            bldr.AddCustomAttributes(
                new ServiceAttribute(
                    UniversalAttributeId.ServiceAvailability,
                    ServiceElement.CreateNumericalServiceElement(ElementType.UInt8, 255)),
                new ServiceAttribute(
                    UniversalAttributeId.ServiceInfoTimeToLive,
                    ServiceElement.CreateNumericalServiceElement(ElementType.UInt32, 56623104))
                );
            DoTest(ServiceRecordBuilderTests_Data.OnePlusNamePlusCustomTwo, bldr);
        }
Ejemplo n.º 28
0
        public void CustomDuplicateTwoEnumNonGeneric()
        {
            // Note: not checking here WHEN the exception is thrown...
            ServiceRecordBuilder bldr = new ServiceRecordBuilder();

            bldr.AddServiceClass(BluetoothService.SerialPort);
            bldr.ServiceName = "Hello World!";
            ServiceAttribute[] array = new ServiceAttribute[] {
                new ServiceAttribute(
                    UniversalAttributeId.ServiceAvailability,
                    ServiceElement.CreateNumericalServiceElement(ElementType.UInt8, 255)),
                new ServiceAttribute(
                    UniversalAttributeId.ServiceAvailability,
                    ServiceElement.CreateNumericalServiceElement(ElementType.UInt8, 0x55))
            };
            System.Collections.IEnumerable eble = array;
            bldr.AddCustomAttributes(eble);
            DoTestFailsBuilderOrLater(bldr);
        }
        private static ServiceRecord CreateAVariousRecord()
        {
            MyFunc <ElementType, ServiceAttributeId> createId = delegate(ElementType etX) {
                return((ServiceAttributeId)0x4000 + checked ((byte)etX));
            };
            ServiceRecordBuilder bldr = new ServiceRecordBuilder();

            bldr.AddServiceClass(BluetoothService.HealthDevice);
            bldr.ServiceName = "alan";
            IList <ServiceAttribute> attrList = new List <ServiceAttribute>();
            ElementType et_;

#if SUPPORT_NIL
            et_ = ElementType.Nil;
            attrList.Add(new ServiceAttribute(createId(et_), new ServiceElement(et_, null)));
#endif
            et_ = ElementType.Boolean;
            attrList.Add(new ServiceAttribute(createId(et_), new ServiceElement(et_, true)));
            ElementType[] weee =
            {
                ElementType.UInt8, ElementType.UInt16, ElementType.UInt32, //UInt64, UInt128,
                ElementType.Int8,  ElementType.Int16, ElementType.Int32,   //Int64, Int128,
            };
            foreach (ElementType et in weee)
            {
                attrList.Add(new ServiceAttribute(
                                 createId(et),
                                 ServiceElement.CreateNumericalServiceElement(et, (uint)et)));
            }
            et_ = ElementType.Uuid16;
            attrList.Add(new ServiceAttribute(createId(et_),
                                              new ServiceElement(et_, (UInt16)et_)));
            et_ = ElementType.Uuid32;
            attrList.Add(new ServiceAttribute(createId(et_),
                                              new ServiceElement(et_, (UInt32)et_)));
            et_ = ElementType.Uuid128;
            attrList.Add(new ServiceAttribute(createId(et_),
                                              new ServiceElement(et_, BluetoothService.CreateBluetoothUuid((int)et_))));
            bldr.AddCustomAttributes(attrList);
            bldr.AddCustomAttributes(ElementsAndVariableAndFixedInDeepTree1());
            ServiceRecord record = bldr.ServiceRecord;
            return(record);
        }
Ejemplo n.º 30
0
        protected override void AddSimpleServiceRecord(out ServiceRecord fullServiceRecord,
                                                       int livePort, Guid serviceClass, string serviceName)
        {
#if SdpService_CreateL2Cap
            var livePort16 = checked ((UInt16)livePort);
            //m_sdpService = SdpService.CreateL2Cap(
            //    serviceClass,
            //    serviceName, livePort16, m_factory);
#endif
            ServiceRecordBuilder bldrDummy = new ServiceRecordBuilder();
            bldrDummy.ProtocolType = BluetoothProtocolDescriptorType.L2Cap;
            bldrDummy.AddServiceClass(serviceClass);
            bldrDummy.ServiceName = serviceName;
            fullServiceRecord     = bldrDummy.ServiceRecord;
#if SdpService_CreateL2Cap
            ServiceRecordHelper.SetL2CapChannelNumber(fullServiceRecord,
                                                      livePort16);
#else
            AddCustomServiceRecord(ref fullServiceRecord, livePort);
#endif
        }
Ejemplo n.º 31
0
    static void Documentation_SRB_ToByteArray_Pbap()
    {
        ServiceRecordBuilder bldr = new ServiceRecordBuilder();

        bldr.AddServiceClass(BluetoothService.PhonebookAccessPse);
        bldr.ServiceName = "Phonebook Access PSE";
        bldr.AddBluetoothProfileDescriptor(BluetoothService.PhonebookAccess, 1, 0); // v1.0
        const ushort SupportedRepositories = 0x0314;

        bldr.AddCustomAttribute(new ServiceAttribute(SupportedRepositories,
                                                     ServiceElement.CreateNumericalServiceElement(ElementType.UInt8, 0x03)));
        //
        ServiceRecord record = bldr.ServiceRecord;
        //
        var txt = ServiceRecordUtilities.Dump(record);

        Console.WriteLine(txt);
        //
        var byteArr = record.ToByteArray();
        var txtBA   = BitConverter.ToString(byteArr);

        Console.WriteLine(txtBA);
    }
Ejemplo n.º 32
0
 private static ServiceRecord CreateBasicRfcommRecord(Guid serviceClassUuid, String svcName)
 {
     ServiceRecordBuilder bldr = new ServiceRecordBuilder();
     System.Diagnostics.Debug.Assert(bldr.ProtocolType == BluetoothProtocolDescriptorType.Rfcomm);
     bldr.AddServiceClass(serviceClassUuid);
     if (svcName != null) {
         bldr.ServiceName = svcName;
     }
     return bldr.ServiceRecord;
 }