Example #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();
            }
        }
Example #2
0
        protected override void SetService(byte[] sdpRecord, ServiceClass cod)
        {
            int    used;
            IntPtr rec = NativeMethods.sdp_extract_pdu(sdpRecord, sdpRecord.Length, out used);

            if (used != sdpRecord.Length)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                                                                  "sdp_extract_pdu had {0} but only used {1}", sdpRecord.Length, used));
            }
            _sdpSession = AddRecord(rec);
            //???NativeMethods.sdp_free_record(pRec);
            Console.WriteLine("Done SetService");
        }
Example #3
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);
        }
Example #4
0
 internal static extern BluezError sdp_record_register(NativeMethods.SdpSessionSafeHandle /*"sdp_session_t*"*/ session,
                                                       IntPtr /*"sdp_record_t*"*/ rec, byte flags);