예제 #1
0
        //--------
        private static void SetPointerToArray <T>(List <IntPtr> listAllocs,
                                                  ref Structs.SDP_Data_Element parent,
                                                  T[] child)
            where T : struct
        {
            var    sizeOfElem = Marshal.SizeOf(typeof(T));
            IntPtr pAlloc     = Marshal.AllocHGlobal(sizeOfElem * child.Length);

            listAllocs.Add(pAlloc);
            IntPtr pCur = pAlloc;

            for (int i = 0; i < child.Length; ++i)
            {
                Marshal.StructureToPtr(child[i], pCur, false);
                // Next
                pCur = PointerAdd(pCur, sizeOfElem);
            }//for
            //
            var iPtr     = pAlloc.ToInt64();
            var bytesPtr = BitConverter.GetBytes(iPtr);

            parent.FakeAtUnionPosition  = bytesPtr[0];
            parent.FakeAtUnionPosition1 = bytesPtr[1];
            parent.FakeAtUnionPosition2 = bytesPtr[2];
            parent.FakeAtUnionPosition3 = bytesPtr[3];
            parent.FakeAtUnionPosition4 = bytesPtr[4];
            parent.FakeAtUnionPosition5 = bytesPtr[5];
            parent.FakeAtUnionPosition6 = bytesPtr[6];
            parent.FakeAtUnionPosition7 = bytesPtr[7];
        }
예제 #2
0
        public void UInt64()
        {
            var listAllocs = new List <IntPtr>();
            //
            var elemData = new Structs.SDP_Data_Element(
                StackConsts.SDP_Data_Element_Type.UnsignedInteger8Bytes, 8);

            elemData.FakeAtUnionPosition7 = 0xF5;
            elemData.FakeAtUnionPosition6 = 0x23;
            elemData.FakeAtUnionPosition5 = 0x45;
            elemData.FakeAtUnionPosition4 = 0x67;
            elemData.FakeAtUnionPosition3 = 0x4a;
            elemData.FakeAtUnionPosition2 = 0x5b;
            elemData.FakeAtUnionPosition1 = 0x6c;
            elemData.FakeAtUnionPosition  = 0x7d;
            ServiceRecord r = DoTestParseOneAttribute(listAllocs, elemData, 0x1234);
            //
            var attr = r[0];

            Assert.AreEqual(unchecked ((ServiceAttributeId)0x1234), attr.Id, "AttrId");
            Assert.AreEqual(0x1234, attr.IdAsOrdinalNumber, "IdAsOrdinalNumber");
            Assert.AreEqual(ElementType.UInt64, attr.Value.ElementType, "ET");
            Assert.AreEqual(ElementTypeDescriptor.UnsignedInteger, attr.Value.ElementTypeDescriptor, "ETD");
            Assert.AreEqual(0xF52345674a5b6c7d, attr.Value.Value, "v");
            //
            Free(listAllocs);
        }
예제 #3
0
        internal static IntPtr ProtoDListMake(List <IntPtr> listAllocs, byte port)
        {
            IntPtr pCur;
            var    elemDataRfcomm = new Structs.SDP_Data_Element(
                StackConsts.SDP_Data_Element_Type.UUID_16, 2);

            elemDataRfcomm.FakeAtUnionPosition  = 0x00; // TODO Endian???!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            elemDataRfcomm.FakeAtUnionPosition1 = 0x03;
            IntPtr pCurRfcomm = CopyToNative(listAllocs, ref elemDataRfcomm);
            //
            var elemDataScn = new Structs.SDP_Data_Element(
                StackConsts.SDP_Data_Element_Type.UnsignedInteger1Byte, 1);

            elemDataScn.FakeAtUnionPosition = port;
            IntPtr pCurScn = CopyToNative(listAllocs, ref elemDataScn);
            //
            var elemListL1Arr = new[] { elemDataRfcomm, elemDataScn };
            var elemListL1    = new Structs.SDP_Data_Element(
                StackConsts.SDP_Data_Element_Type.Sequence, 2);

            SetPointerToArray(listAllocs, ref elemListL1, elemListL1Arr);
            IntPtr pelemListL1 = CopyToNative(listAllocs, ref elemListL1);
            //
            var elemDataL2Cap = new Structs.SDP_Data_Element(
                StackConsts.SDP_Data_Element_Type.UUID_16, 2);

            elemDataL2Cap.FakeAtUnionPosition  = 0x01;
            elemDataL2Cap.FakeAtUnionPosition1 = 0x00;
            IntPtr pCurL2Cap = CopyToNative(listAllocs, ref elemDataL2Cap);
            //
            var elemListL0Arr = new[] { elemDataL2Cap };
            var elemListL0    = new Structs.SDP_Data_Element(
                StackConsts.SDP_Data_Element_Type.Sequence, 1);

            SetPointerToArray(listAllocs, ref elemListL0, elemListL0Arr);
            IntPtr pelemListL0 = CopyToNative(listAllocs, ref elemListL0);
            //
            var elemListRootArr = new[] { elemListL0, elemListL1 };
            var elemListRoot    = new Structs.SDP_Data_Element(
                StackConsts.SDP_Data_Element_Type.Sequence, 2);

            SetPointerToArray(listAllocs, ref elemListRoot, elemListRootArr);
            IntPtr pelemListRoot = CopyToNative(listAllocs, ref elemListRoot);
            //
            var attrData = new Structs.SDP_Service_Attribute_Value_Data(0x4, pelemListRoot);

            pCur = CopyToNative(listAllocs, ref attrData);
            var attrRsp = new Structs.SDP_Service_Attribute_Response_Data(1, pCur);

            pCur = CopyToNative(listAllocs, ref attrRsp);
            return(pCur);
        }
예제 #4
0
        public void NULL()
        {
            var listAllocs = new List <IntPtr>();
            //
            var elemData = new Structs.SDP_Data_Element(
                StackConsts.SDP_Data_Element_Type.NULL, 1);
            ServiceRecord r = DoTestParseOneAttribute(listAllocs, elemData, 0xF123);
            //
            var attr = r[0];

            Assert.AreEqual(unchecked ((ServiceAttributeId)0xF123), attr.Id, "AttrId");
            Assert.AreEqual(ElementType.Nil, attr.Value.ElementType, "ET");
            Assert.AreEqual(ElementTypeDescriptor.Nil, attr.Value.ElementTypeDescriptor, "ET");
            Assert.AreEqual(null, attr.Value.Value, "v");
            //
            Free(listAllocs);
        }
예제 #5
0
        public void String()
        {
            var listAllocs = new List <IntPtr>();
            //
            var strBytes = new byte[] { (byte)'a', (byte)'b', (byte)'c', (byte)'d', };
            var elem     = new Structs.SDP_Data_Element(
                StackConsts.SDP_Data_Element_Type.TextString, checked ((uint)strBytes.Length));

            SetPointerToArray(listAllocs, ref elem, strBytes);
            ServiceRecord r = DoTestParseOneAttribute(listAllocs, elem, 0x1234);
            //
            var attr = r[0];

            Assert.AreEqual(unchecked ((ServiceAttributeId)0x1234), attr.Id, "AttrId");
            Assert.AreEqual(ElementType.TextString, attr.Value.ElementType, "ET");
            Assert.AreEqual("abcd", attr.Value.GetValueAsStringUtf8(), "value");
            //
            Free(listAllocs);
        }
예제 #6
0
        static void Boolean_(bool expected, byte byteValue)
        {
            var listAllocs = new List <IntPtr>();
            //
            var elemData = new Structs.SDP_Data_Element(
                StackConsts.SDP_Data_Element_Type.Boolean, 1);

            elemData.FakeAtUnionPosition = byteValue;
            ServiceRecord r = DoTestParseOneAttribute(listAllocs, elemData, 0xF123);
            //
            var attr = r[0];

            Assert.AreEqual(unchecked ((ServiceAttributeId)0xF123), attr.Id, "AttrId");
            Assert.AreEqual(ElementType.Boolean, attr.Value.ElementType, "ET");
            Assert.AreEqual(ElementTypeDescriptor.Boolean, attr.Value.ElementTypeDescriptor, "ET");
            Assert.AreEqual(expected, attr.Value.Value, "v");
            //
            Free(listAllocs);
        }
예제 #7
0
        public void UInt8()
        {
            var    listAllocs = new List <IntPtr>();
            IntPtr pCur;
            //
            var elemData = new Structs.SDP_Data_Element(
                StackConsts.SDP_Data_Element_Type.UnsignedInteger1Byte, 1);

            elemData.FakeAtUnionPosition = 0xF5;
            pCur = CopyToNative(listAllocs, ref elemData);
            //
            var attrData = new Structs.SDP_Service_Attribute_Value_Data(0xF123, pCur);

            pCur = CopyToNative(listAllocs, ref attrData);
            //
            var attrRsp = new Structs.SDP_Service_Attribute_Response_Data(1, pCur);

            pCur = CopyToNative(listAllocs, ref attrRsp);
            //
            var svcSrchAttrRsp = new Structs.SDP_Response_Data__SDP_Service_Search_Attribute_Response_Data(
                StackConsts.SDP_Response_Data_Type.ServiceSearchAttributeResponse,
                1, pCur);

            pCur = CopyToNative(listAllocs, ref svcSrchAttrRsp);
            //
            var stuff = Create_BluetopiaSdpQuery();
            List <ServiceRecord> rList = stuff.DutSdpQuery.BuildRecordList(pCur);

            Assert.AreEqual(1, rList.Count);
            ServiceRecord r = rList[0];
            //
            var attr = r[0];

            Assert.AreEqual(unchecked ((ServiceAttributeId)0xF123), attr.Id, "AttrId");
            //Assert.AreEqual(unchecked((short)0xF123), attr.IdAsOrdinalNumber, "IdAsOrdinalNumber");
            Assert.AreEqual(ElementType.UInt8, attr.Value.ElementType, "ET");
            Assert.AreEqual(ElementTypeDescriptor.UnsignedInteger, attr.Value.ElementTypeDescriptor, "ET");
            Assert.AreEqual(0xF5, attr.Value.Value, "v");
            //
            Free(listAllocs);
        }
예제 #8
0
        public void UInt128()
        {
            var listAllocs = new List <IntPtr>();
            //
            var elemData = new Structs.SDP_Data_Element(
                StackConsts.SDP_Data_Element_Type.UnsignedInteger16Bytes, 16);

            elemData.FakeAtUnionPositionF = 0xF5;
            elemData.FakeAtUnionPositionE = 0x23;
            elemData.FakeAtUnionPositionD = 0x45;
            elemData.FakeAtUnionPositionC = 0x67;
            elemData.FakeAtUnionPositionB = 0x4a;
            elemData.FakeAtUnionPositionA = 0x5b;
            elemData.FakeAtUnionPosition9 = 0x6c;
            elemData.FakeAtUnionPosition8 = 0x7d;
            elemData.FakeAtUnionPosition7 = 0x01;
            elemData.FakeAtUnionPosition6 = 0x02;
            elemData.FakeAtUnionPosition5 = 0x03;
            elemData.FakeAtUnionPosition4 = 0x04;
            elemData.FakeAtUnionPosition3 = 0x05;
            elemData.FakeAtUnionPosition2 = 0x06;
            elemData.FakeAtUnionPosition1 = 0x07;
            elemData.FakeAtUnionPosition  = 0x08;
            ServiceRecord r = DoTestParseOneAttribute(listAllocs, elemData, 0x1234);
            //
            var attr = r[0];

            Assert.AreEqual(unchecked ((ServiceAttributeId)0x1234), attr.Id, "AttrId");
            Assert.AreEqual(0x1234, attr.IdAsOrdinalNumber, "IdAsOrdinalNumber");
            Assert.AreEqual(ElementType.UInt128, attr.Value.ElementType, "ET");
            Assert.AreEqual(ElementTypeDescriptor.UnsignedInteger, attr.Value.ElementTypeDescriptor, "ETD");
            var expectedValue = new byte[] {
                0xF5, 0x23, 0x45, 0x67, 0x4a, 0x5b, 0x6c, 0x7d,
                0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
            };

            Assert.AreEqual(expectedValue, attr.Value.Value, "v");
            //
            Free(listAllocs);
        }
예제 #9
0
        public void Int8()
        {
            var    listAllocs = new List <IntPtr>();
            IntPtr pCur;
            //
            var elemData = new Structs.SDP_Data_Element(
                StackConsts.SDP_Data_Element_Type.SignedInteger1Byte, 1);

            elemData.FakeAtUnionPosition = 0xF5;
            pCur = CopyToNative(listAllocs, ref elemData);
            ServiceRecord r = DoTestParseOneAttribute(listAllocs, elemData, 0xF123);
            //
            var attr = r[0];

            Assert.AreEqual(unchecked ((ServiceAttributeId)0xF123), attr.Id, "AttrId");
            //Assert.AreEqual(unchecked((short)0xF123), attr.IdAsOrdinalNumber, "IdAsOrdinalNumber");
            Assert.AreEqual(ElementType.Int8, attr.Value.ElementType, "ET");
            Assert.AreEqual(ElementTypeDescriptor.TwosComplementInteger, attr.Value.ElementTypeDescriptor, "ET");
            Assert.AreEqual(unchecked ((sbyte)0xF5), attr.Value.Value, "v");
            //
            Free(listAllocs);
        }
예제 #10
0
        public void Uuid32()
        {
            var listAllocs = new List <IntPtr>();
            //
            var elemData = new Structs.SDP_Data_Element(
                StackConsts.SDP_Data_Element_Type.UUID_32, 4);

            elemData.FakeAtUnionPosition  = 0xF5;
            elemData.FakeAtUnionPosition1 = 0x23;
            elemData.FakeAtUnionPosition2 = 0x45;
            elemData.FakeAtUnionPosition3 = 0x67;
            ServiceRecord r = DoTestParseOneAttribute(listAllocs, elemData, 0x1234);
            //
            var attr = r[0];

            Assert.AreEqual(unchecked ((ServiceAttributeId)0x1234), attr.Id, "AttrId");
            Assert.AreEqual(0x1234, attr.IdAsOrdinalNumber, "IdAsOrdinalNumber");
            Assert.AreEqual(ElementType.Uuid32, attr.Value.ElementType, "ET");
            Assert.AreEqual(ElementTypeDescriptor.Uuid, attr.Value.ElementTypeDescriptor, "ET");
            Assert.AreEqual(0xF5234567, attr.Value.Value, "v");
            //
            Free(listAllocs);
        }
예제 #11
0
        private static ServiceRecord DoTestParseOneAttribute(List <IntPtr> listAllocs, Structs.SDP_Data_Element elem, ushort attrId)
        {
            IntPtr        pCur;
            ServiceRecord r;
            IntPtr        pElem = CopyToNative(listAllocs, ref elem);
            //
            var attrData = new Structs.SDP_Service_Attribute_Value_Data(
                attrId, pElem);

            pCur = CopyToNative(listAllocs, ref attrData);
            var attrRsp = new Structs.SDP_Service_Attribute_Response_Data(1, pCur);

            pCur = CopyToNative(listAllocs, ref attrRsp);
            //
            var stuff = Create_BluetopiaSdpQuery();

            r = stuff.DutSdpQuery.BuildRecord(pCur);
            return(r);
        }