//---- private static SdpDiscoveryRecordsBufferBase.SimpleInfo Create_SI( Guid serviceClass, BluetoothProtocolDescriptorType pdlType, int scn) { Guid info_serviceUuid = serviceClass; int info_scn; if (pdlType == BluetoothProtocolDescriptorType.Rfcomm || pdlType == BluetoothProtocolDescriptorType.GeneralObex) { if (scn == -1) { throw new ArgumentException("scn"); } info_scn = scn; } else { if (scn != -1) { throw new ArgumentException("scn"); } info_scn = -1; } return(new SdpDiscoveryRecordsBufferBase.SimpleInfo( info_serviceUuid, info_scn)); }
static ServiceElement GetChannelElement(ServiceRecord record, BluetoothProtocolDescriptorType proto) { if (!record.Contains(AttributeIds.ProtocolDescriptorList)) { goto NotFound; } ServiceAttribute attr = record.GetAttributeById(AttributeIds.ProtocolDescriptorList); return(GetChannelElement(attr, proto, out _)); NotFound: return(null); }
static ServiceElement GetChannelElement(ServiceRecord record, BluetoothProtocolDescriptorType proto) { if (!record.Contains(UniversalAttributeId.ProtocolDescriptorList)) { goto NotFound; } ServiceAttribute attr = record.GetAttributeById(UniversalAttributeId.ProtocolDescriptorList); bool?isSimpleRfcomm; return(GetChannelElement(attr, proto, out isSimpleRfcomm)); NotFound: return(null); }
// TODO GetRfcommChannelElement(ServiceAttribute attr) Could be public -> Tests! internal static ServiceElement GetChannelElement(ServiceAttribute attr, BluetoothProtocolDescriptorType proto, #if !V1 out bool?isSimpleRfcomm #else out object isSimpleRfcomm
// TODO GetRfcommChannelElement(ServiceAttribute attr) Could be public -> Tests! internal static ServiceElement GetChannelElement(ServiceAttribute attr, BluetoothProtocolDescriptorType proto, out bool?isSimpleRfcomm) { if (proto != BluetoothProtocolDescriptorType.L2Cap && proto != BluetoothProtocolDescriptorType.Rfcomm) { throw new ArgumentException("Can only fetch RFCOMM or L2CAP element."); } // isSimpleRfcomm = true; Debug.Assert(attr != null, "attr != null"); ServiceElement e0 = attr.Value; if (e0.ElementType == ElementType.ElementAlternative) { Trace.WriteLine("Don't support ElementAlternative ProtocolDescriptorList values."); goto NotFound; } else if (e0.ElementType != ElementType.ElementSequence) { Trace.WriteLine("Bad ProtocolDescriptorList base element."); goto NotFound; } IList <ServiceElement> protoStack = e0.GetValueAsElementList(); IEnumerator <ServiceElement> etor = protoStack.GetEnumerator(); ServiceElement layer; IList <ServiceElement> layerContent; ServiceElement channelElement; // -- L2CAP Layer -- if (!etor.MoveNext()) { Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "Protocol stack truncated before {0}.", "L2CAP")); goto NotFound; } layer = etor.Current; //cast here are for non-Generic version. layerContent = layer.GetValueAsElementList(); if (layerContent[0].GetValueAsUuid() != BluetoothProtocol.L2CapProtocol) { Trace.WriteLine(String.Format(CultureInfo.InvariantCulture, "Bad protocol stack, layer {0} is not {1}.", 1, "L2CAP")); goto NotFound; } bool hasPsmEtc = layerContent.Count != 1; // Cast for FX1.1 object isSimpleRfcomm = (bool)isSimpleRfcomm && !hasPsmEtc; if (proto == BluetoothProtocolDescriptorType.L2Cap) { if (layerContent.Count < 2) { Trace.WriteLine("L2CAP PSM element was requested but the L2CAP layer in this case hasn't a second element."); goto NotFound; } channelElement = (ServiceElement)layerContent[1]; goto Success; } // // -- RFCOMM Layer -- if (!etor.MoveNext()) { Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "Protocol stack truncated before {0}.", "RFCOMM")); goto NotFound; } layer = etor.Current; layerContent = layer.GetValueAsElementList(); if (layerContent[0].GetValueAsUuid() != BluetoothProtocol.RFCommProtocol) { Trace.WriteLine(String.Format(CultureInfo.InvariantCulture, "Bad protocol stack, layer {0} is not {1}.", 2, "RFCOMM")); goto NotFound; } // if (layerContent.Count < 2) { Trace.WriteLine(String.Format(CultureInfo.InvariantCulture, "Bad protocol stack, layer {0} hasn't a second element.", 2)); goto NotFound; } channelElement = (ServiceElement)layerContent[1]; if (channelElement.ElementType != ElementType.UInt8) { Trace.WriteLine(String.Format(CultureInfo.InvariantCulture, "Bad protocol stack, layer {0} is not UInt8.", 2)); goto NotFound; } // Success // // -- Any remaining layer(s) -- bool extraLayers = etor.MoveNext(); isSimpleRfcomm = (bool)isSimpleRfcomm && !extraLayers; Success: // return(channelElement); NotFound: isSimpleRfcomm = null; return(null); }