コード例 #1
0
        public void L2CapGetChannelByte_0xF0F9()
        {
            ServiceRecord rcd   = ServiceRecord.CreateServiceRecordFromBytes(Data_CompleteThirdPartyRecords.SemcHla);
            int           value = ServiceRecordHelper.GetL2CapChannelNumber(rcd);

            Assert.AreEqual(0xF0F9, value);
        }
コード例 #2
0
        public void L2CapGetChannelByte_None()
        {
            ServiceRecord rcd   = ServiceRecord.CreateServiceRecordFromBytes(Data_CompleteThirdPartyRecords.XpFsquirtOpp);
            int           value = ServiceRecordHelper.GetL2CapChannelNumber(rcd);

            Assert.AreEqual(-1, value);
        }
コード例 #3
0
        public void L2CapGetChannelByte_0x000F()
        {
            ServiceRecord rcd   = ServiceRecord.CreateServiceRecordFromBytes(Data_CompleteThirdPartyRecords.XpB_1of2_1115);
            int           value = ServiceRecordHelper.GetL2CapChannelNumber(rcd);

            Assert.AreEqual(0x0F, value);
        }
コード例 #4
0
        public void GetChannelElement_AttrNotExists()
        {
            ServiceRecord  rcd     = new ServiceRecord();
            ServiceElement element = ServiceRecordHelper.GetRfcommChannelElement(rcd);

            Assert.IsNull(element);
        }
コード例 #5
0
        public void L2CapGetChannelElement_None()
        {
            ServiceRecord  rcd     = ServiceRecord.CreateServiceRecordFromBytes(Data_CompleteThirdPartyRecords.XpFsquirtOpp);
            ServiceElement element = ServiceRecordHelper.GetL2CapChannelElement(rcd);

            Assert.IsNull(element);
        }
コード例 #6
0
        public void GetChannelElement_SdpNone()
        {
            ServiceRecord  rcd     = ServiceRecord.CreateServiceRecordFromBytes(Data_CompleteThirdPartyRecords.XpB_0of2Sdp);
            ServiceElement element = ServiceRecordHelper.GetRfcommChannelElement(rcd);

            Assert.IsNull(element);
        }
コード例 #7
0
        public void GetPrimarySvcClassId_Opp()
        {
            ServiceRecord rcd = ServiceRecord.CreateServiceRecordFromBytes(Data_CompleteThirdPartyRecords.PalmOsOpp);
            Guid          id  = ServiceRecordHelper._GetPrimaryServiceClassId(rcd);

            Assert.AreEqual(BluetoothService.ObexObjectPush, id);
        }
コード例 #8
0
        public void GetChannelByte_SdpNone()
        {
            ServiceRecord rcd   = ServiceRecord.CreateServiceRecordFromBytes(Data_CompleteThirdPartyRecords.XpB_0of2Sdp);
            int           value = ServiceRecordHelper.GetRfcommChannelNumber(rcd);

            Assert.AreEqual(-1, value);
        }
コード例 #9
0
        public void GetChannelByte_PdlHasUuid128s()
        {
            ServiceRecord rcd   = ServiceRecord.CreateServiceRecordFromBytes(Data_CompleteThirdPartyRecords.KingSt_d2r1_withPdlUuid128s);
            int           value = ServiceRecordHelper.GetRfcommChannelNumber(rcd);

            Assert.AreEqual(2, value);
        }
コード例 #10
0
        public void GetChannelByte_AttrNotExists()
        {
            ServiceRecord rcd   = new ServiceRecord();
            int           value = ServiceRecordHelper.GetRfcommChannelNumber(rcd);

            Assert.AreEqual(-1, value);
        }
コード例 #11
0
ファイル: ObexListener.cs プロジェクト: jehy/32feet.NET
        private static ServiceRecord CreateServiceRecord()
        {
            ServiceElement englishUtf8PrimaryLanguage = CreateEnglishUtf8PrimaryLanguageServiceElement();
            ServiceRecord  record = new ServiceRecord(
                new ServiceAttribute(InTheHand.Net.Bluetooth.AttributeIds.UniversalAttributeId.ServiceClassIdList,
                                     new ServiceElement(ElementType.ElementSequence,
                                                        new ServiceElement(ElementType.Uuid16, (UInt16)0x1105))),
                new ServiceAttribute(InTheHand.Net.Bluetooth.AttributeIds.UniversalAttributeId.ProtocolDescriptorList,
                                     ServiceRecordHelper.CreateGoepProtocolDescriptorList()),
#if ADD_SERVICE_NAME_TO_SDP_RECORD
                // Could add ServiceName, ProviderName etc here.
                new ServiceAttribute(InTheHand.Net.Bluetooth.AttributeIds.UniversalAttributeId.LanguageBaseAttributeIdList,
                                     englishUtf8PrimaryLanguage),
                new ServiceAttribute(ServiceRecord.CreateLanguageBasedAttributeId(
                                         InTheHand.Net.Bluetooth.AttributeIds.UniversalAttributeId.ProviderName,
                                         LanguageBaseItem.PrimaryLanguageBaseAttributeId),
                                     new ServiceElement(ElementType.TextString, "32feet.NET")),
#endif
                //
                new ServiceAttribute(InTheHand.Net.Bluetooth.AttributeIds.ObexAttributeId.SupportedFormatsList,
                                     new ServiceElement(ElementType.ElementSequence,
                                                        new ServiceElement(ElementType.UInt8, (byte)0xFF)))
                );

            return(record);
        }
コード例 #12
0
        protected override void AddCustomServiceRecord(ref ServiceRecord fullServiceRecord, int livePort)
        {
            var livePort16 = checked ((UInt16)livePort);

            ServiceRecordHelper.SetL2CapPsmNumber(fullServiceRecord,
                                                  livePort16);
            m_sdpService = SdpService.CreateCustom(fullServiceRecord, m_factory);
        }
コード例 #13
0
        protected override void AddCustomServiceRecord(ref ServiceRecord fullServiceRecord, int livePort)
        {
            var livePortB = checked ((byte)livePort);

            ServiceRecordHelper.SetRfcommChannelNumber(fullServiceRecord,
                                                       livePortB);
            m_sdpService = SdpService.CreateCustom(fullServiceRecord, m_factory);
        }
コード例 #14
0
        public void GetChannelByte_Opp()
        {
            ServiceRecord rcd   = ServiceRecord.CreateServiceRecordFromBytes(Data_CompleteThirdPartyRecords.PalmOsOpp);
            int           value = ServiceRecordHelper.GetRfcommChannelNumber(rcd);

            Assert.AreNotEqual(-1, value);
            Assert.AreEqual(Data_CompleteThirdPartyRecords.PalmOsOpp_RfcommChannelNumber, (byte)value);
        }
コード例 #15
0
        public void GetChannelElement_Opp()
        {
            ServiceRecord  rcd     = ServiceRecord.CreateServiceRecordFromBytes(Data_CompleteThirdPartyRecords.PalmOsOpp);
            ServiceElement element = ServiceRecordHelper.GetRfcommChannelElement(rcd);

            Assert.IsNotNull(element);
            Assert.AreEqual(ElementType.UInt8, element.ElementType);
            Assert.AreEqual(Data_CompleteThirdPartyRecords.PalmOsOpp_RfcommChannelNumber, element.Value);
        }
コード例 #16
0
        public void GetChannelByte_Bad_PdlEmptyList()
        {
            ServiceRecord rcd = new ServiceRecord(
                new ServiceAttribute(UniversalAttributeId.ProtocolDescriptorList,
                                     new ServiceElement(ElementType.ElementSequence)));
            int value = ServiceRecordHelper.GetRfcommChannelNumber(rcd);

            Assert.AreEqual(-1, value);
        }
コード例 #17
0
        public void TestCreateAVariousRecord()
        {
            ServiceRecord record = CreateAVariousRecord();

#if false
            TestWcLsnrBluetoothFactory f = new TestWcLsnrBluetoothFactory();
            BluetoothFactory.SetFactory(f);
            //----
            int port = 19;
            ServiceRecordHelper.SetRfcommChannelNumber(record, port);
            //
            ISdpService     x0 = SdpService.CreateCustom(record);
            TestSdpService2 x  = (TestSdpService2)x0;
#endif
            TestWcLsnrBluetoothFactory f      = new TestWcLsnrBluetoothFactory();
            TestLsnrRfCommIf           commIf = new TestLsnrRfCommIf();
            f.queueIRfCommIf.Enqueue(commIf);
            TestLsnrRfcommPort port0 = new TestLsnrRfcommPort();
            f.queueIRfCommPort.Enqueue(port0);
            BluetoothFactory.SetFactory(f);
            //
            port0.SetOpenServerResult(PORT_RETURN_CODE.SUCCESS);
            BluetoothListener lsnr = new BluetoothListener(BluetoothService.VideoSource,
                                                           record);
            lsnr.Start();
            int port = lsnr.LocalEndPoint.Port;
            lsnr.Stop();
            //
            TestSdpService2 x = f.GetTestSdpService();
            x.AssertCalls(
                // Well-known
                "AddServiceClassIdList: <00001400-0000-1000-8000-00805f9b34fb>" + NewLine
                + "AddRFCommProtocolDescriptor: " + port + NewLine
                // Eeeeeeech, how to detect all possible LangOffset_WellKnown strings!!!!
                + "AddAttribute: id: 0x0006, dt: DATA_ELE_SEQ, len: 9, val: "
                + "09-65-6E-" + "09-00-6A-" + "09-01-00" + NewLine
                + "AddAttribute: id: 0x0100, dt: TEXT_STR, len: 4, val: 61-6C-61-6E" + NewLine
                + "AddAttribute: id: 0x0401, dt: DATA_ELE_ALT, len: 66, val: "
                + "35-2F-35-2D-25-0C-61-62-63-64-C3-A9-66-67-68-C4-"
                + "AD-6A-45-1A-68-74-74-70-3A-2F-2F-65-78-61-6D-70-"
                + "6C-65-2E-63-6F-6D-2F-66-6F-6F-2E-74-78-74-09-FE-"
                + "12-25-0C-61-62-63-64-C3-A9-66-67-68-C4-AD-6A-09-"
                + "12-34" + NewLine
                + "AddAttribute: id: 0x4015, dt: UINT, len: 1, val: 15" + NewLine
                + "AddAttribute: id: 0x4016, dt: UINT, len: 2, val: 00-16" + NewLine
                + "AddAttribute: id: 0x4017, dt: UINT, len: 4, val: 00-00-00-17" + NewLine
                + "AddAttribute: id: 0x401E, dt: TWO_COMP_INT, len: 1, val: 1E" + NewLine
                + "AddAttribute: id: 0x401F, dt: TWO_COMP_INT, len: 2, val: 00-1F" + NewLine
                + "AddAttribute: id: 0x4020, dt: TWO_COMP_INT, len: 4, val: 00-00-00-20" + NewLine
                + "AddAttribute: id: 0x4028, dt: UUID, len: 2, val: 00-28" + NewLine
                + "AddAttribute: id: 0x4029, dt: UUID, len: 4, val: 00-00-00-29" + NewLine
                + "AddAttribute: id: 0x402A, dt: UUID, len: 16, val: 00-00-00-2A-00-00-10-00-80-00-00-80-5F-9B-34-FB" + NewLine
                + "AddAttribute: id: 0x402C, dt: BOOLEAN, len: 1, val: 01" + NewLine
                );
        }
コード例 #18
0
ファイル: BluetopiaListener.cs プロジェクト: jehy/32feet.NET
        //--
        // The structs I created for creating SDP records are totally wrong,
        // so this doesn't work!!!!
        protected override void AddCustomServiceRecord(ref ServiceRecord fullServiceRecord, int livePort)
        {
            var livePortB = checked ((byte)livePort);

            ServiceRecordHelper.SetRfcommChannelNumber(fullServiceRecord,
                                                       livePortB);
            var sdpCtor = new BluetopiaSdpCreator(_fcty);

            sdpCtor.CreateServiceRecord(fullServiceRecord);
            _sdpCtor = sdpCtor;
        }
コード例 #19
0
        internal static List <int> ListAllL2CapPortsInRecords(List <ServiceRecord> list)
        {
            var portList = new List <int>();

            foreach (var curSR in list)
            {
                int possiblePort = ServiceRecordHelper.GetL2CapChannelNumber(curSR);
                portList.Add(possiblePort);
            }//for
            return(portList);
        }
コード例 #20
0
        public void PalmOsOppCompleteRecord()
        {
            ServiceRecord record = CreatePalmOsOppCompleteRecord();

            ServiceRecordHelper.SetRfcommChannelNumber(record, 1);
            byte[] buf    = new byte[256];
            int    length = new ServiceRecordCreator().CreateServiceRecord(record, buf);

            //ServiceRecordUtilities.Dump(Console.Out, record);
            Assert2.AreEqualBuffers(Data_CompleteThirdPartyRecords.PalmOsOpp_HackMadeFirstLengthOneByteField, buf, length);
        }
コード例 #21
0
        public void GetChannelByte_Bad_TruncatedBeforeRfcomm()
        {
            var layer0 = new ServiceElement(ElementType.ElementSequence,
                                            new ServiceElement(ElementType.Uuid16, Uuid16_L2CapProto)); // not L2CAP
            ServiceRecord rcd = new ServiceRecord(
                new ServiceAttribute(UniversalAttributeId.ProtocolDescriptorList,
                                     new ServiceElement(ElementType.ElementSequence,
                                                        layer0)));
            int value = ServiceRecordHelper.GetRfcommChannelNumber(rcd);

            Assert.AreEqual(-1, value);
        }
コード例 #22
0
        public void CreateL2Cap()
        {
            ServiceElement element = ServiceRecordHelper.CreateL2CapProtocolDescriptorList();
            //
            List_ServiceAttribute attrs = new List_ServiceAttribute();

            attrs.Add(new ServiceAttribute(UniversalAttributeId.ProtocolDescriptorList, element));
            ServiceRecord record = new ServiceRecord(attrs);
            String        dump   = ServiceRecordUtilities.Dump(record);

            Assert.AreEqual(ExpectedL2CapDump, dump, "L2CAP ProtoDL dump");
        }
コード例 #23
0
        public void GetChannelByte_Bad_PdlFirstNotL2CAP()
        {
            var layer0Bad = new ServiceElement(ElementType.ElementSequence,
                                               new ServiceElement(ElementType.Uuid16, Uuid16_Wierdo)); // not L2CAP
            var layer1 = new ServiceElement(ElementType.ElementSequence,
                                            new ServiceElement(ElementType.Uuid16, Uuid16_RfcommProto),
                                            ServiceElement.CreateNumericalServiceElement(ElementType.UInt8, 5)); // RFCOMM
            ServiceRecord rcd = new ServiceRecord(
                new ServiceAttribute(UniversalAttributeId.ProtocolDescriptorList,
                                     new ServiceElement(ElementType.ElementSequence,
                                                        layer0Bad, layer1)));
            int value = ServiceRecordHelper.GetRfcommChannelNumber(rcd);

            Assert.AreEqual(-1, value);
        }
コード例 #24
0
        public void GetChannelByte_Bad_RfcommPortElementNotUint8()
        {
            var layer0 = new ServiceElement(ElementType.ElementSequence,
                                            new ServiceElement(ElementType.Uuid16, Uuid16_L2CapProto));    // L2CAP
            var layer1Bad = new ServiceElement(ElementType.ElementSequence,
                                               new ServiceElement(ElementType.Uuid16, Uuid16_RfcommProto), //RFCOMM
                                               ServiceElement.CreateNumericalServiceElement(ElementType.UInt16, 5));
            ServiceRecord rcd = new ServiceRecord(
                new ServiceAttribute(UniversalAttributeId.ProtocolDescriptorList,
                                     new ServiceElement(ElementType.ElementSequence,
                                                        layer0, layer1Bad)));
            int value = ServiceRecordHelper.GetRfcommChannelNumber(rcd);

            Assert.AreEqual(-1, value);
        }
コード例 #25
0
ファイル: Bluetooth.cs プロジェクト: jehy/32feet.NET
        public void GoodOne()
        {
            Guid          uuid = BluetoothService.GenericAudio;
            ServiceRecord rcd  = new ServiceRecord(
                new ServiceAttribute(InTheHand.Net.Bluetooth.AttributeIds.UniversalAttributeId.ServiceClassIdList,
                                     new ServiceElement(ElementType.ElementSequence,
                                                        new ServiceElement(ElementType.Uuid128, uuid))),
                new ServiceAttribute(InTheHand.Net.Bluetooth.AttributeIds.UniversalAttributeId.ProtocolDescriptorList,
                                     ServiceRecordHelper.CreateRfcommProtocolDescriptorList())
                );
            BluetoothListener lsnr = new BluetoothListener(uuid, rcd);

            lsnr.Start();
            lsnr.Stop();
        }
コード例 #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);
        }
コード例 #27
0
ファイル: Bluetooth.cs プロジェクト: jehy/32feet.NET
        public void GoodOneDifferentUuids_EndPoint()
        {
            Guid          uuid1 = BluetoothService.GenericAudio;
            Guid          uuid2 = BluetoothService.HardcopyCableReplacement;
            ServiceRecord rcd   = new ServiceRecord(
                new ServiceAttribute(InTheHand.Net.Bluetooth.AttributeIds.UniversalAttributeId.ServiceClassIdList,
                                     new ServiceElement(ElementType.ElementSequence,
                                                        new ServiceElement(ElementType.Uuid128, uuid1))),
                new ServiceAttribute(InTheHand.Net.Bluetooth.AttributeIds.UniversalAttributeId.ProtocolDescriptorList,
                                     ServiceRecordHelper.CreateRfcommProtocolDescriptorList())
                );
            BluetoothListener lsnr = new BluetoothListener(new BluetoothEndPoint(BluetoothAddress.None, uuid2), rcd);

            lsnr.Start();
            lsnr.Stop();
        }
コード例 #28
0
        public ServiceRecord CreatePalmOsOppCompleteRecord()
        {
            List_ServiceAttribute attrs = new List_ServiceAttribute();
            ServiceElement        element;
            List_ServiceElement   list;

            //
            attrs.Add(new ServiceAttribute(UniversalAttributeId.ServiceRecordHandle,
                                           new ServiceElement(ElementType.UInt32, (UInt32)0x10001)));
            //
            element = new ServiceElement(ElementType.Uuid16, (UInt16)0x1105);
            list    = new List_ServiceElement();
            list.Add(element);
            element = new ServiceElement(ElementType.ElementSequence, list);
            attrs.Add(new ServiceAttribute(UniversalAttributeId.ServiceClassIdList, element));
            //
            element = ServiceRecordHelper.CreateGoepProtocolDescriptorList();
            attrs.Add(new ServiceAttribute(UniversalAttributeId.ProtocolDescriptorList, element));
            //
            const UInt16 Windows1252EncodingId = 2252;

            LanguageBaseItem[] languages =
            {
                new LanguageBaseItem("en", Windows1252EncodingId, LanguageBaseItem.PrimaryLanguageBaseAttributeId)
            };
            element = LanguageBaseItem.CreateElementSequenceFromList(languages);
            attrs.Add(new ServiceAttribute(UniversalAttributeId.LanguageBaseAttributeIdList, element));
            //
            // PalmOs really uses Windows-1252, but since the string is ASCII, UTF-8 is equivalent.
            element = new ServiceElement(ElementType.TextString, "OBEX Object Push");
            attrs.Add(new ServiceAttribute(
                          ServiceRecord.CreateLanguageBasedAttributeId(UniversalAttributeId.ServiceName,
                                                                       LanguageBaseItem.PrimaryLanguageBaseAttributeId),
                          element));
            //
            list = new List_ServiceElement();
            list.Add(new ServiceElement(ElementType.UInt8, (byte)0x1));
            list.Add(new ServiceElement(ElementType.UInt8, (byte)0x2));
            list.Add(new ServiceElement(ElementType.UInt8, (byte)0x3));
            list.Add(new ServiceElement(ElementType.UInt8, (byte)0xFF));
            element = new ServiceElement(ElementType.ElementSequence, list);
            attrs.Add(new ServiceAttribute(ObexAttributeId.SupportedFormatsList, element));
            //
            ServiceRecord record = new ServiceRecord(attrs);

            return(record);
        }
コード例 #29
0
        //--------
        bool WriteWellKnownAttribute(ServiceAttribute attr, ISdpService sdpService) //, ServiceRecord record)
        {
            switch (attr.Id)
            {
            case UniversalAttributeId.ServiceClassIdList:
                sdpService.AddServiceClassIdList(ServiceRecordHelper_GetServiceClassIdList(attr));
                return(true);

            case UniversalAttributeId.ProtocolDescriptorList:
                bool?          isSimpleRfcomm;
                ServiceElement el = ServiceRecordHelper.GetChannelElement(attr,
                                                                          BluetoothProtocolDescriptorType.Rfcomm, out isSimpleRfcomm);
                if (el == null)
                {
                    return(false);    // Non-RFCOMM
                }
                int       scn      = ServiceRecordHelper.GetRfcommChannelNumber(el);
                const int NotFound = -1;
                if (scn == NotFound)
                {
                    Debug.Fail("scn == -1 but non-RFCOMM case should be detected above!!?");
                    return(false);
                }
                else
                {
                    Debug.Assert(isSimpleRfcomm.HasValue, "isRfcommPlusMore.HasValue");
                    if (isSimpleRfcomm == true)
                    {
                        sdpService.AddRFCommProtocolDescriptor(checked ((byte)scn));
                    }
                    else
                    {
                        Debug.Assert(!isSimpleRfcomm.Value, "!isSimpleRfcomm");
                        // Need more layers (etc)!  Could call AddProtocolList() with
                        // three (or more) tSDP_PROTOCOL_ELEM.  But just fall
                        // back to raw dumping for now.
                        return(false);
                    }
                }
                return(true);

            default:
                return(false);
            }
        }
コード例 #30
0
        public void CreateL2CapNapEmptyNetProtoList()
        {
            var netProtoList = new ServiceElement(ElementType.ElementSequence
                                                  );
            var layer1 = new ServiceElement(ElementType.ElementSequence,
                                            new ServiceElement(ElementType.Uuid16, Uuid16_BnepProto),
                                            ServiceElement.CreateNumericalServiceElement(ElementType.UInt16, 0x0100), //v1.0
                                            netProtoList
                                            );
            ServiceElement element = ServiceRecordHelper.CreateL2CapProtocolDescriptorListWithUpperLayers(
                layer1);
            //
            List_ServiceAttribute attrs = new List_ServiceAttribute();

            attrs.Add(new ServiceAttribute(UniversalAttributeId.ProtocolDescriptorList, element));
            ServiceRecord record = new ServiceRecord(attrs);
            String        dump   = ServiceRecordUtilities.Dump(record);

            Assert.AreEqual(ExpectedL2CapNapDumpEmptyNetProtoList, dump, "L2CAP NAP ProtoDL dump");
        }