예제 #1
0
        //----
        internal List <ServiceRecord> DoSdpQueryWithConnect(
            BluetoothAddress addr, Guid svcClass, bool rfcommOnly)
        {
            var svcUuid = new Structs.uuid_t(svcClass);

            //:TestUuids();

            // Connect
            byte[] target = BluezUtils.FromBluetoothAddress(addr);
            Console.WriteLine("Gonna sdp_connect (SafeHandle)...");
            NativeMethods.SdpSessionSafeHandle session = NativeMethods.sdp_connect(StackConsts.BDADDR_ANY,
                                                                                   target, StackConsts.SdpConnectFlags.SDP_RETRY_IF_BUSY);
            if (session.IsInvalid)
            {
                //BluezUtils.Throw((BluezError)(-1), "sdp_connect");
                const int WSASERVICE_NOT_FOUND = 10108;
                throw new SocketException(WSASERVICE_NOT_FOUND);
            }
            try {
                // Query
                return(DoSdpQuery(session, svcUuid, rfcommOnly));
            } finally {
                session.Close();
            }
        }
예제 #2
0
 internal static void Test()
 {
     if (!_TestUuidsOnce)
     {
         _TestUuidsOnce = true;
         var u16 = new Structs.uuid_t((UInt16)0x0100);
         DumpUuidt(u16);
         var u32 = new Structs.uuid_t((UInt32)0x00000100);
         DumpUuidt(u32);
         var u128 = new Structs.uuid_t(BluetoothService.L2CapProtocol);
         DumpUuidt(u128);
     }
 }
예제 #3
0
            internal static void DumpUuidt(Structs.uuid_t uuid)
            {
                var sizeOf = Marshal.SizeOf(uuid);
                var p      = Marshal.AllocHGlobal(sizeOf);

                Marshal.StructureToPtr(uuid, p, false);
                try {
                    var arr = new byte[sizeOf];
                    Marshal.Copy(p, arr, 0, arr.Length);
                    Console.WriteLine("uuid_t: {0} (len: {1})",
                                      BitConverter.ToString(arr), sizeOf);
                } finally {
                    Marshal.FreeHGlobal(p);
                }
            }
예제 #4
0
        List <ServiceRecord> DoSdpQuery(NativeMethods.SdpSessionSafeHandle session,
                                        Structs.uuid_t svcUuid, bool rfcommOnly)
        {
            var    listAllocs = new List <IntPtr>();
            IntPtr searchList = BluezUtils.sdp_list_append(IntPtr.Zero, svcUuid, listAllocs);

            // Attribute pattern
            IntPtr attridList;

            StackConsts.sdp_attrreq_type_t reqType;
            Console.WriteLine("rfcommOnly: " + rfcommOnly);
            if (rfcommOnly)
            {
                const UInt16 ClassListId  = (ushort)UniversalAttributeId.ServiceClassIdList;     //=1
                const UInt16 ProtoDListId = (ushort)UniversalAttributeId.ProtocolDescriptorList; //=4
                reqType    = StackConsts.sdp_attrreq_type_t.SDP_ATTR_REQ_INDIVIDUAL;
                attridList = BluezUtils.sdp_list_append(IntPtr.Zero, ClassListId, listAllocs);
                attridList = BluezUtils.sdp_list_append(attridList, ProtoDListId, listAllocs);
            }
            else
            {
                const UInt32 allAttributes = 0x0000ffff;
                reqType    = StackConsts.sdp_attrreq_type_t.SDP_ATTR_REQ_RANGE;
                attridList = BluezUtils.sdp_list_append(IntPtr.Zero, allAttributes, listAllocs);
            }

            // Query
            Console.WriteLine("sdp_service_search_attr_req in:"
                              + " {0}, attrid_list: {1}",
                              searchList, attridList);
            IntPtr     pResponseList;
            BluezError ret = NativeMethods.sdp_service_search_attr_req(session,
                                                                       searchList,
                                                                       reqType, attridList,
                                                                       out pResponseList);

            Console.WriteLine("sdp_service_search_attr_req ret: {0}, result: {1}",
                              ret, pResponseList);
            BluezUtils.CheckAndThrow(ret, "sdp_service_search_attr_req");
            //
            var rList = BuildRecordList(pResponseList);

            return(rList);
        }