Example #1
0
        private void connectToPc()
        {
            try
            {
                LogMessage("Connecting to PC...");
                string imsi = m_MbnInterfaceManager.GetInterface(selectedInterfaceId).GetSubscriberInformation().SubscriberID;

                IMbnConnection connection = ((IMbnConnection[])m_MbnConnectionManager.GetConnections())[0];
                string         profileXml = String.Format(
                    @"<MBNProfile xmlns='http://www.microsoft.com/networking/WWAN/profile/v1'>
    <Name>tempProfile</Name>
    <IsDefault>false</IsDefault>
    <SubscriberID>{0}</SubscriberID>
    <Context>
        <AccessString>ID{1}</AccessString>
    </Context>
</MBNProfile>", imsi, txtAPN.Text);
                uint requestId;
                //connection
                connection.Connect(MBN_CONNECTION_MODE.MBN_CONNECTION_MODE_TMP_PROFILE, profileXml, out requestId);
            }
            catch (Exception ex)
            {
                LogMessage("Connect failed - " + ex.ToString());
                LogMessage("Connect failed - " + ex.ToString());
            }
        }
Example #2
0
        public void OnConnectStateChange(IMbnConnection newConnection)
        {
            MBN_ACTIVATION_STATE activationState;
            string profileName;

            newConnection.GetConnectionState(out activationState, out profileName);
            Console.WriteLine("OnConnectStateChange - " + profileName + " - " + activationState);
        }
Example #3
0
 private void ProcessOnDisconnectComplete(IMbnConnection connection, uint requestId, int status)
 {
     LogMessage("Disconnected from PC");
     this.Invoke((MethodInvoker) delegate()
     {
         btnPcConnect.Enabled    = true;
         btnPcDisconnect.Enabled = false;
     });
 }
        public void OnDisconnectComplete(IMbnConnection connection, uint requestId, int status)
        {
            OnDisconnectCompleteHandler callback;

            if (m_DisconnectCallback.TryGetTarget(out callback))
            {
                callback.Invoke(connection, requestId, status);
            }
        }
        async void ProcessOnDisconnectComplete(IMbnConnection connection, uint requestId, int status)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                string message = "";

                message += "\nOnDisconnectComplete event received. Request ID: " + requestId.ToString() + " status: 0x" + status.ToString("X");
                rootPage.NotifyUser(message, NotifyType.StatusMessage);
            });
        }
Example #6
0
        // This will be called back when connect operation is complete
        public void OnConnectComplete(IMbnConnection connection, uint requestId, int status)
        {
            // Invoke main page thread to show UI
            OnConnectCompleteHandler callback;

            if (m_ConnectCallback.TryGetTarget(out callback))
            {
                callback.Invoke(connection, requestId, status);
            }
        }
Example #7
0
        private void cmbRadio_SelectedIndexChanged(object sender, EventArgs e)
        {
            selectedInterfaceId = radios[cmbRadio.SelectedIndex].InterfaceID;
            InitializeEventHandlers();
            uint age = 0;

            lvNetwork.Items.Clear();
            try
            {
                lastScannedNetworks = (MBN_PROVIDER[])m_MbnInterface.GetVisibleProviders(out age);
                PopulateNetworks(lastScannedNetworks);
                lblLastScan.Text = DateTime.Now.AddSeconds(-1 * age).ToShortTimeString();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Networks not found.  Please scan to find networks.");
                lblLastScan.Text = "Unknown";
            }

            //Fill In the registration stuff
            IMbnRegistration registrationInterface = m_MbnInterface as IMbnRegistration;

            updateRegistration(registrationInterface);

            //Fill in the IMSI
            try
            {
                string IMSI = m_MbnInterfaceManager.GetInterface(selectedInterfaceId).GetSubscriberInformation().SubscriberID;
                lblIMSI.Text = IMSI;
            } catch (Exception ex)
            {
                lblIMSI.Text = "Unknown";
            }

            //Check if connected
            try
            {
                IMbnConnection       connection = ((IMbnConnection[])m_MbnConnectionManager.GetConnections())[0];
                MBN_ACTIVATION_STATE activationState;
                string profileName;
                connection.GetConnectionState(out activationState, out profileName);
                if (activationState == MBN_ACTIVATION_STATE.MBN_ACTIVATION_STATE_ACTIVATED)
                {
                    btnPcConnect.Enabled = false;
                }
                else
                {
                    btnPcDisconnect.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                btnPcDisconnect.Enabled = false;
            }
        }
Example #8
0
 private void disconnectFromPc()
 {
     try
     {
         LogMessage("Disconnecting from PC...");
         IMbnConnection connection = ((IMbnConnection[])m_MbnConnectionManager.GetConnections())[0];
         uint           requestId;
         connection.Disconnect(out requestId);
     }
     catch (Exception ex)
     {
         LogMessage("Disconnect failed - " + ex.ToString());
     }
 }
Example #9
0
        private void mobile_connect_button_Click(object sender, RoutedEventArgs e)
        {
            //connect to mobile profile
            mobile_password_label.Content = "Connected to Mobile Broadband Network";

            MBNConnect.MBNConnect allive             = new MBNConnect.MBNConnect();
            MbnInterfaceManager   mbnInfMgr          = new MbnInterfaceManager();
            IMbnInterfaceManager  mbnInfMgrInterface = mbnInfMgr as IMbnInterfaceManager;

            IMbnInterface[] mobileInterfaces = mbnInfMgrInterface.GetInterfaces() as IMbnInterface[];
            IMbnInterface   inf  = (IMbnInterface)mobileInterfaces[1];
            IMbnConnection  conn = inf.GetConnection();

            allive.KeepConnectionAllive(conn);
        }
Example #10
0
        private void ProcessOnConnectComplete(IMbnConnection connection, uint requestId, int status)
        {
            MBN_ACTIVATION_STATE activationState;
            string profileName;

            connection.GetConnectionState(out activationState, out profileName);
            LogMessage("ProcessOnConnectComplete - " + profileName + " - " + activationState);
            if (activationState == MBN_ACTIVATION_STATE.MBN_ACTIVATION_STATE_ACTIVATED)
            {
                this.Invoke((MethodInvoker) delegate()
                {
                    btnPcConnect.Enabled    = false;
                    btnPcDisconnect.Enabled = true;
                });
            }
        }
Example #11
0
        public bool KeepConnectionAllive(IMbnConnection newConnection)
        {
            //check every 30 sec if mobile connection is still active
            MBN_ACTIVATION_STATE activationState;
            string profileName;

            newConnection.GetConnectionState(out activationState, out profileName);

            Console.WriteLine("OnConnectStateChange - " + profileName + " - " + activationState);

            if (activationState.ToString() == "connected")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private void RegisterForNotifications()
        {
            try
            {
                if (m_MbnInterface == null)
                {
                    m_MbnInterface = GetFirstInterface();
                }

                if (m_MbnConnection == null)
                {
                    m_MbnConnection = m_MbnInterface.GetConnection();
                }

                if (m_MbnDeviceServicesContext == null)
                {
                    m_MbnDeviceServicesContext = m_MbnDeviceServicesManager.GetDeviceServicesContext(m_MbnInterface.InterfaceID);
                }

                // Register for IMbnInterfaceManagerEvents
                if (m_InterfaceManagerEventsSink == null)
                {
                    m_OnInterfaceArrivalEventDelegate = new OnInterfaceArrivalHandler(ProcessOnInterfaceArrival);
                    m_OnInterfaceRemovalEventDelegate = new OnInterfaceRemovalHandler(ProcessOnInterfaceRemoval);
                    m_InterfaceManagerEventsSink      = new InterfaceManagerEventsSink(m_OnInterfaceArrivalEventDelegate,
                                                                                       m_OnInterfaceRemovalEventDelegate,
                                                                                       GetMbnInterfaceManagerEventsConnectionPoint());
                }

                // Register for IMbnPinManagerEvents
                if (m_PinManagerEventsSink == null)
                {
                    m_OnGetPinStateCompleteEventDelegate = new OnGetPinStateCompleteHandler(ProcessOnGetPinStateCompleteHandlerEvt);
                    m_PinManagerEventsSink = new PinManagerEventsSink(m_OnGetPinStateCompleteEventDelegate, GetMbnPinManagerEventsConnectionPoint());
                }

                // Register for IMbnPinEvents
                if (m_PinEventsSink == null)
                {
                    m_OnEnterCompleteEventDelegate = new OnEnterCompleteHandler(ProcessOnEnterComplete);
                    m_PinEventsSink = new PinEventsSink(m_OnEnterCompleteEventDelegate, GetMbnPinEventsConnectionPoint());
                }
                // Register for IMbnConnectionEvents

                if (m_ConnectionEventsSink == null)
                {
                    m_OnConnectCompleteEventDelegate    = new OnConnectCompleteHandler(ProcessOnConnectComplete);
                    m_OnDisconnectCompleteEventDelegate = new OnDisconnectCompleteHandler(ProcessOnDisconnectComplete);
                    m_ConnectionEventsSink = new ConnectionEventsSink(m_OnConnectCompleteEventDelegate,
                                                                      m_OnDisconnectCompleteEventDelegate,
                                                                      GetMbnConnectionEventsConnectionPoint());
                }
                // Register for IMbnDeviceServicesEvents

                if (m_DeviceServicesEventsSink == null)
                {
                    m_OnOpenCommandSessionCompleteEventDelegate = new OnOpenCommandSessionCompleteHandler(ProcessOnOpenCommandSessionComplete);
                    m_OnQueryCommandCompleteEventDelegate       = new OnQueryCommandCompleteHandler(ProcessOnQueryCommandComplete);
                    m_OnCloseCommandSessionEventDelegate        = new OnCloseCommandSessionCompleteHandler(ProcessOnCloseCommandSessionComplete);
                    m_DeviceServicesEventsSink = new DeviceServicesEventsSink(
                        m_OnOpenCommandSessionCompleteEventDelegate,
                        m_OnQueryCommandCompleteEventDelegate,
                        m_OnCloseCommandSessionEventDelegate,
                        GetMbnDeviceServicesEventsConnectionPoint());
                }
            }
            catch (Exception e)
            {
                rootPage.NotifyUser(ParseExceptionCode(e), NotifyType.ErrorMessage);
            }
        }
Example #13
0
        private void InitializeEventHandlers()
        {
            try
            {
                // Get the interface
                m_MbnInterface             = m_MbnInterfaceManager.GetInterface(selectedInterfaceId);
                m_MbnConnection            = m_MbnInterface.GetConnection();
                m_MbnDeviceServicesContext = m_MbnDeviceServicesManager.GetDeviceServicesContext(m_MbnInterface.InterfaceID);

                // Register for IMbnConnectionEvents
                if (m_ConnectionEventsSink == null)
                {
                    m_OnConnectCompleteEventDelegate    = new OnConnectCompleteHandler(ProcessOnConnectComplete);
                    m_OnDisconnectCompleteEventDelegate = new OnDisconnectCompleteHandler(ProcessOnDisconnectComplete);
                    m_ConnectionEventsSink = new ConnectionEventsSink(m_OnConnectCompleteEventDelegate,
                                                                      m_OnDisconnectCompleteEventDelegate,
                                                                      GetMbnConnectionEventsConnectionPoint());
                }

                // Register for IMbnDeviceServicesEvents
                if (m_DeviceServicesEventsSink == null)
                {
                    m_OnOpenCommandSessionCompleteEventDelegate = new OnOpenCommandSessionCompleteHandler(ProcessOnOpenCommandSessionComplete);
                    m_OnQueryCommandCompleteEventDelegate       = new OnQueryCommandCompleteHandler(ProcessOnQueryCommandComplete);
                    m_OnSetCommandCompleteEventDelegate         = new OnSetCommandCompleteHandler(ProcessOnSetCommandComplete);
                    m_OnCloseCommandSessionEventDelegate        = new OnCloseCommandSessionCompleteHandler(ProcessOnCloseCommandSessionComplete);
                    m_DeviceServicesEventsSink = new DeviceServicesEventsSink(
                        m_OnOpenCommandSessionCompleteEventDelegate,
                        m_OnQueryCommandCompleteEventDelegate,
                        m_OnCloseCommandSessionEventDelegate,
                        m_OnSetCommandCompleteEventDelegate,
                        GetMbnDeviceServicesEventsConnectionPoint());
                }

                //Register for IMbnRegistrationEvents
                if (m_RegistrationEventsSink == null)
                {
                    m_OnRegisterModeAvailableHandlerEventDelegate    = new OnRegisterModeAvailableHandler(ProcessOnRegisterModeAvailable);
                    m_OnRegisterStateChangeHandlerEventDelegate      = new OnRegisterStateChangeHandler(ProcessOnRegisterStateChange);
                    m_OnPacketServiceStateChangeHandlerEventDelegate = new OnPacketServiceStateChangeHandler(ProcessOnPacketServiceStateChange);
                    m_OnSetRegisterModeCompleteHandlerEventDelegate  = new OnSetRegisterModeCompleteHandler(ProcessOnSetRegisterModeComplete);
                    m_RegistrationEventsSink = new RegistrationEventsSink(
                        m_OnRegisterModeAvailableHandlerEventDelegate,
                        m_OnRegisterStateChangeHandlerEventDelegate,
                        m_OnPacketServiceStateChangeHandlerEventDelegate,
                        m_OnSetRegisterModeCompleteHandlerEventDelegate,
                        GetRegisterEventsConnectionPoint());
                }

                if (m_InterfaceEventsSink == null)
                {
                    OnEmergencyModeChangeHandlerEventDelegate           = new OnEmergencyModeChangeHandler(ProcessOnEmergencyModeChange);
                    OnHomeProviderAvailableHandlerEventDelegate         = new OnHomeProviderAvailableHandler(ProcessOnHomeProviderAvailable);
                    OnInterfaceCapabilityAvailableHandlerEventDelegate  = new OnInterfaceCapabilityAvailableHandler(ProcessOnInterfaceCapabilityAvailable);
                    OnPreferredProvidersChangeHandlerEventDelegate      = new OnPreferredProvidersChangeHandler(ProcessOnPreferredProvidersChange);
                    OnReadyStateChangeHandlerEventDelegate              = new OnReadyStateChangeHandler(ProcessOnReadyStateChange);
                    OnScanNetworkCompleteHandlerEventDelegate           = new OnScanNetworkCompleteHandler(ProcessOnScanNetworkComplete);
                    OnSetPreferredProvidersCompleteHandlerEventDelegate = new OnSetPreferredProvidersCompleteHandler(ProcessOnSetPreferredProvidersComplete);
                    OnSubscriberInformationChangeHandlerEventDelegate   = new OnSubscriberInformationChangeHandler(ProcessOnSubscriberInformationChange);
                    m_InterfaceEventsSink = new InterfaceEventsSink(
                        OnEmergencyModeChangeHandlerEventDelegate,
                        OnHomeProviderAvailableHandlerEventDelegate,
                        OnInterfaceCapabilityAvailableHandlerEventDelegate,
                        OnPreferredProvidersChangeHandlerEventDelegate,
                        OnReadyStateChangeHandlerEventDelegate,
                        OnScanNetworkCompleteHandlerEventDelegate,
                        OnSetPreferredProvidersCompleteHandlerEventDelegate,
                        OnSubscriberInformationChangeHandlerEventDelegate,
                        GetInterfaceEventsConnectionPoint());
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(ParseExceptionCode(e));
            }
        }
Example #14
0
 public void OnDisconnectComplete(IMbnConnection newConnection, uint requestID, int status)
 {
     Console.WriteLine("OnDisconnectComplete");
 }
Example #15
0
        async void ProcessOnDisconnectComplete(IMbnConnection connection, uint requestId, int status)
        {
            // Dispatch to UI thread
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                string message = "";

                message += "\nOnDisconnectComplete event received. Request ID: " + requestId.ToString() + " status: 0x" + status.ToString("X");
                rootPage.NotifyUser(message, NotifyType.StatusMessage);
            });
        }
Example #16
0
 public void OnVoiceCallStateChange(IMbnConnection connection) { }
 // Not implemented for sample
 public void OnConnectStateChange(IMbnConnection connection)
 {
 }
Example #18
0
 // Not implemented for sample
 public void OnConnectStateChange(IMbnConnection connection)
 {
     Console.WriteLine("OnConnectStateChange");
 }
Example #19
0
        public void Test()
        {
            IMbnInterfaceManager      interfaceManager = null;
            IMbnInterface             inf        = null;
            IMbnSubscriberInformation subscriber = null;

            try
            {
                interfaceManager = (IMbnInterfaceManager) new MbnInterfaceManager();
                inf        = interfaceManager.GetInterface(InterfaceID);
                subscriber = inf.GetSubscriberInformation();

                uint outCode = 0;
                inf.ScanNetwork(out outCode);

                uint age   = 0;
                var  array = inf.GetVisibleProviders(out age);

                var provider = inf.GetHomeProvider();

                //inf.SetPreferredProviders(new MBN_PROVIDER[] { plusProvider }, out outCode);

                XmlDocument xml = new XmlDocument();
                xml.LoadXml(mobileProfileTemplate);

                xml["MBNProfile"]["SubscriberID"].InnerText = subscriber.SubscriberID;
                xml["MBNProfile"]["SimIccID"].InnerText     = subscriber.SimIccID;

                //Console.WriteLine("Profile: " + xml.OuterXml);

                IMbnConnection conn = null;

                try
                {
                    conn = inf.GetConnection();

                    //MBN_ACTIVATION_STATE state;
                    //string profile;
                    //conn.GetConnectionState(out state, out profile);

                    uint requestId;
                }
                finally
                {
                    if (conn != null)
                    {
                        Marshal.FinalReleaseComObject(conn);
                    }
                }
            }
            finally
            {
                if (subscriber != null)
                {
                    Marshal.FinalReleaseComObject(subscriber);
                }
                if (inf != null)
                {
                    Marshal.FinalReleaseComObject(inf);
                }
                if (interfaceManager != null)
                {
                    Marshal.FinalReleaseComObject(interfaceManager);
                }
            }
        }
Example #20
0
        void ExecuteAction(ActionType action)
        {
            IMbnInterfaceManager      interfaceManager = null;
            IMbnInterface             inf        = null;
            IMbnSubscriberInformation subscriber = null;

            try
            {
                interfaceManager = (IMbnInterfaceManager) new MbnInterfaceManager();
                inf        = interfaceManager.GetInterface(InterfaceID);
                subscriber = inf.GetSubscriberInformation();

                XmlDocument xml = new XmlDocument();
                xml.LoadXml(mobileProfileTemplate);

                xml["MBNProfile"]["SubscriberID"].InnerText = subscriber.SubscriberID;
                xml["MBNProfile"]["SimIccID"].InnerText     = subscriber.SimIccID;

                //Console.WriteLine("Profile: " + xml.OuterXml);

                IMbnConnection conn = null;

                try
                {
                    conn = inf.GetConnection();

                    //MBN_ACTIVATION_STATE state;
                    //string profile;
                    //conn.GetConnectionState(out state, out profile);

                    uint requestId;

                    if (action == ActionType.Connect)
                    {
                        conn.Connect(MBN_CONNECTION_MODE.MBN_CONNECTION_MODE_TMP_PROFILE, xml.OuterXml, out requestId);
                    }
                    else
                    {
                        conn.Disconnect(out requestId);
                    }
                }
                finally
                {
                    if (conn != null)
                    {
                        Marshal.FinalReleaseComObject(conn);
                    }
                }
            }
            finally
            {
                if (subscriber != null)
                {
                    Marshal.FinalReleaseComObject(subscriber);
                }
                if (inf != null)
                {
                    Marshal.FinalReleaseComObject(inf);
                }
                if (interfaceManager != null)
                {
                    Marshal.FinalReleaseComObject(interfaceManager);
                }
            }
        }
Example #21
0
        // Register for notifications
        private void RegisterForNotifications()
        {
            try
            {
                if (m_MbnInterface == null)
                {
                    // Get the interface
                    m_MbnInterface = GetFirstInterface();
                }

                if (m_MbnConnection == null)
                {
                    m_MbnConnection = m_MbnInterface.GetConnection();
                }

                if (m_MbnDeviceServicesContext == null)
                {
                    m_MbnDeviceServicesContext = m_MbnDeviceServicesManager.GetDeviceServicesContext(m_MbnInterface.InterfaceID);
                }

                // Register for IMbnInterfaceManagerEvents
                if (m_InterfaceManagerEventsSink == null)
                {
                    m_OnInterfaceArrivalEventDelegate = new OnInterfaceArrivalHandler(ProcessOnInterfaceArrival);
                    m_OnInterfaceRemovalEventDelegate = new OnInterfaceRemovalHandler(ProcessOnInterfaceRemoval);
                    m_InterfaceManagerEventsSink = new InterfaceManagerEventsSink(m_OnInterfaceArrivalEventDelegate,
                                                                                  m_OnInterfaceRemovalEventDelegate,
                                                                                  GetMbnInterfaceManagerEventsConnectionPoint());
                }

                // Register for IMbnPinManagerEvents
                if (m_PinManagerEventsSink == null)
                {
                    m_OnGetPinStateCompleteEventDelegate = new OnGetPinStateCompleteHandler(ProcessOnGetPinStateCompleteHandlerEvt);
                    m_PinManagerEventsSink = new PinManagerEventsSink(m_OnGetPinStateCompleteEventDelegate, GetMbnPinManagerEventsConnectionPoint());
                }

                // Register for IMbnPinEvents
                if (m_PinEventsSink == null)
                {
                    m_OnEnterCompleteEventDelegate = new OnEnterCompleteHandler(ProcessOnEnterComplete);
                    m_PinEventsSink = new PinEventsSink(m_OnEnterCompleteEventDelegate, GetMbnPinEventsConnectionPoint());
                }
                
                // Register for IMbnConnectionEvents
                if (m_ConnectionEventsSink == null)
                {
                    m_OnConnectCompleteEventDelegate = new OnConnectCompleteHandler(ProcessOnConnectComplete);
                    m_OnDisconnectCompleteEventDelegate = new OnDisconnectCompleteHandler(ProcessOnDisconnectComplete);
                    m_ConnectionEventsSink = new ConnectionEventsSink(m_OnConnectCompleteEventDelegate,
                                                                      m_OnDisconnectCompleteEventDelegate,
                                                                      GetMbnConnectionEventsConnectionPoint());
                }
                
                // Register for IMbnDeviceServicesEvents
                if (m_DeviceServicesEventsSink == null)
                {
                    m_OnOpenCommandSessionCompleteEventDelegate = new OnOpenCommandSessionCompleteHandler(ProcessOnOpenCommandSessionComplete);
                    m_OnQueryCommandCompleteEventDelegate = new OnQueryCommandCompleteHandler(ProcessOnQueryCommandComplete);
                    m_OnCloseCommandSessionEventDelegate = new OnCloseCommandSessionCompleteHandler(ProcessOnCloseCommandSessionComplete);
                    m_DeviceServicesEventsSink = new DeviceServicesEventsSink(
                                                    m_OnOpenCommandSessionCompleteEventDelegate,
                                                    m_OnQueryCommandCompleteEventDelegate,
                                                    m_OnCloseCommandSessionEventDelegate,
                                                    GetMbnDeviceServicesEventsConnectionPoint());
                }
            }
            catch (Exception e)
            {
                rootPage.NotifyUser(ParseExceptionCode(e), NotifyType.ErrorMessage);
            }
        }
Example #22
0
 // This will be called back when disconnect operation is complete
 public void OnDisconnectComplete(IMbnConnection connection, uint requestId, int status)
 {
     // Invoke main page thread to show UI
     OnDisconnectCompleteHandler callback;
     if (m_DisconnectCallback.TryGetTarget(out callback))
     {
         callback.Invoke(connection, requestId, status);
     }
 }
Example #23
0
 public void OnVoiceCallStateChange(IMbnConnection newConnection)
 {
     Console.WriteLine("OnVoiceCallStateChange");
 }
Example #24
0
 public void OnVoiceCallStateChange(IMbnConnection connection)
 {
 }
Example #25
0
 // Not implemented for sample
 public void OnConnectStateChange(IMbnConnection connection) { }