protected override void DoOpenClient(int scn, BluetoothAddress addressToConnect) { _fcty.CancelAllQueryNames(); var addrX = BluetopiaUtils.BluetoothAddressAsInteger(addressToConnect); int hConn = _fcty.Api.SPP_Open_Remote_Port(_fcty.StackId, addrX, (uint)scn, _callbackAAAA, 0); var ret = (BluetopiaError)hConn; int i; for (i = 0; i < 5 && ret == BluetopiaError.RFCOMM_UNABLE_TO_CONNECT_TO_REMOTE_DEVICE; ++i) { // Sometimes see this error here, my guess is that the baseband // connection used by the SDP Query is closing right when as we // wanted to connect, so we fail to initiate the connect. In // the debugger when we retry it succeeds, so retry. if (i > 0) { Thread.Sleep(100); // Try right away, then after 100ms sleeps } hConn = _fcty.Api.SPP_Open_Remote_Port(_fcty.StackId, addrX, (uint)scn, _callbackAAAA, 0); ret = (BluetopiaError)hConn; } if (i > 0) { Debug.WriteLine("Auto-retry " + i + " after RFCOMM_UNABLE_TO_CONNECT_TO_REMOTE_DEVICE for SPP_Open_Remote_Port"); } BluetopiaUtils.CheckAndThrow(ret, "SPP_Open_Remote_Port"); _hPortClient = checked ((uint)ret); }
//NEW protected new internal IAsyncResult BeginConnect(BluetoothEndPoint bep, //string pin, // AsyncCallback asyncCallback, Object state) //{ // //_hackRemoteAddress = bep.Address; // //_hackRemotePort = checked((byte)bep.Port); // return base.BeginConnect(bep, asyncCallback, state); //} #endregion #region Write protected override void DoWrite(byte[] p_data, ushort len_to_write, out ushort p_len_written) { int writeLen = _fcty.Api.SPP_Data_Write(_fcty.StackId, PortHandle, len_to_write, p_data); var ret = (BluetopiaError)writeLen; BluetopiaUtils.CheckAndThrow(ret, "SPP_Data_Write"); p_len_written = checked ((ushort)writeLen); }
private void ReadName() { byte[] arr = new byte[StackConsts.MAX_NAME_LENGTH]; var ret = _fcty.Api.GAP_Query_Local_Device_Name(_fcty.StackId, arr.Length, arr); BluetopiaUtils.CheckAndThrow(ret, "GAP_Query_Local_Device_Name"); _name = BluetopiaUtils.FromNameString(arr); }
protected override void DoOpenServer(int scn) { int hConn = _fcty.Api.SPP_Open_Server_Port(_fcty.StackId, (uint)scn, _callbackAAAA, 0); var ret = (BluetopiaError)hConn; BluetopiaUtils.CheckAndThrow(ret, "SPP_Open_Remote_Port"); Debug.WriteLine("SPP_Open_Remote_Port portId: " + ret); _hPortServer = checked ((uint)ret); }
void IBluetopiaSecurity.InitStack() { var ret = _factory.Api.GAP_Set_Pairability_Mode(_factory.StackId, StackConsts.GAP_Pairability_Mode.PairableMode); BluetopiaUtils.CheckAndThrow(ret, "GAP_Set_Pairability_Mode"); ret = _factory.Api.GAP_Register_Remote_Authentication( _factory.StackId, _AuthenticateCallback, 0); BluetopiaUtils.CheckAndThrow(ret, "GAP_Register_Remote_Authentication"); }
public void HciAddScoConnection() { var pt = StackConsts.HCI_PACKET_SCO_TYPE__AllThree; // StackConsts.HCI_ERROR_CODE statusCode; var ret = NativeMethods.HCI_Add_SCO_Connection(_fcty.StackId, _hConn.Value, pt, out statusCode); BluetopiaUtils.CheckAndThrow(ret, "HCI_Add_SCO_Connection"); Debug.WriteLine("HCI_Add_SCO_Connection status: " + statusCode); }
public BluetopiaPlaying() { _hciCb = FnCallback; _fcty = BluetoothFactory.GetTheFactoryOfTypeOrDefault <BluetopiaFactory>(); if (_fcty == null) { throw new InvalidOperationException("No Bluetopia stack."); } var ret = NativeMethods.HCI_Register_Event_Callback(_fcty.StackId, _hciCb, 0); BluetopiaUtils.CheckAndThrow(ret, "HCI_Register_Event_Callback"); }
public void HciCreateConnection(BluetoothAddress address) { byte psrm = 0; byte psm = 0; ushort co = 0; byte ars = 1; ushort pt = 0xFFFF; // StackConsts.HCI_ERROR_CODE statusCode; var ret = NativeMethods.HCI_Create_Connection(_fcty.StackId, BluetopiaUtils.BluetoothAddressAsInteger(address), pt, psrm, psm, co, ars, out statusCode); BluetopiaUtils.CheckAndThrow(ret, "HCI_Create_Connection"); Debug.WriteLine("HCI_Create_Connection status: " + statusCode); }
internal BluetopiaRadio(BluetopiaFactory factory) { _fcty = factory; byte[] bd_addr = new byte[StackConsts.BD_ADDR_SIZE]; var ret = _fcty.Api.GAP_Query_Local_BD_ADDR(_fcty.StackId, bd_addr); BluetopiaUtils.CheckAndThrow(ret, "GAP_Query_Local_BD_ADDR"); _addr = BluetopiaUtils.ToBluetoothAddress(bd_addr); // ReadName(); // uint cod; ret = _fcty.Api.GAP_Query_Class_Of_Device(_fcty.StackId, out cod); BluetopiaUtils.CheckAndThrow(ret, "GAP_Query_Class_Of_Device"); _cod = new ClassOfDevice(cod); }
public void SetMode(bool?connectable, bool?discoverable) { if (connectable.HasValue) { var ret = _fcty.Api.GAP_Set_Connectability_Mode(_fcty.StackId, connectable.Value ? StackConsts.GAP_Connectability_Mode.ConnectableMode : StackConsts.GAP_Connectability_Mode.NonConnectableMode); BluetopiaUtils.CheckAndThrow(ret, "GAP_Set_Connectability_Mode"); } if (discoverable.HasValue) { var ret = _fcty.Api.GAP_Set_Discoverability_Mode(_fcty.StackId, discoverable.Value ? StackConsts.GAP_Discoverability_Mode.GeneralDiscoverableMode : StackConsts.GAP_Discoverability_Mode.NonDiscoverableMode, 0); BluetopiaUtils.CheckAndThrow(ret, "GAP_Set_Discoverability_Mode"); } }
//---- protected sealed override void WriteAttribute(ServiceAttribute attr, byte[] buffer, ref int offset) { bool doneKnown = WriteWellKnownAttribute(attr); if (doneKnown) { return; } // base.WriteAttribute(attr, buffer, ref offset); // var e = _element; var ret = AddAttribute(e); BluetopiaUtils.CheckAndThrow(ret, "SDP_Add_Attribute"); _element = null; }
}//class internal IAsyncResult BeginInquiry(int maxDevices, TimeSpan inquiryLength, AsyncCallback callback, object state, BluetoothClient.LiveDiscoveryCallback liveDiscoHandler, object liveDiscoState, DiscoDevsParams args) { CancelAllQueryNames(); return(_inquiryHandler.BeginInquiry(maxDevices, inquiryLength, callback, state, liveDiscoHandler, liveDiscoState, delegate() { BluetopiaError ret = Api.GAP_Perform_Inquiry(StackId, StackConsts.GAP_Inquiry_Type.GeneralInquiry, 0, 0, checked ((uint)inquiryLength.Seconds), checked ((uint)maxDevices), _inquiryEventCallback, 0); BluetopiaUtils.CheckAndThrow(ret, "Btsdk_StartDeviceDiscovery"); }, args)); }