//--------
        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);
            }
        }
Esempio n. 2
0
        //--------
        public static ISdpService CreateRfcomm(
            Guid serviceClass, string serviceName, byte scn, WidcommBluetoothFactoryBase factory)
        {
            if (scn < BluetoothEndPoint.MinScn || scn > BluetoothEndPoint.MaxScn)
            {
                throw new ArgumentOutOfRangeException("scn"
#if !NETCF
                                                      , scn, null
#endif
                                                      );
            }
            ISdpService sdpService = factory.GetWidcommSdpService();
            sdpService.AddServiceClassIdList(serviceClass);
            sdpService.AddRFCommProtocolDescriptor(scn);
            if (serviceName != null)
            {
                sdpService.AddServiceName(serviceName);
            }
            sdpService.CommitRecord();
            return(sdpService);
        }