Good afternoon
I have a strange problem when using the Mobile Broadband Network API (MBN API). When using netshell and running netsh mbn>show interfaces, I receive 1 interface. That's correct because I have one broadband connection on my system.
When I go to my code (which works on other systems) and I do
IMbnInterface[] mobileInterfaces = mbnInfMgrInterface.GetInterfaces() as IMbnInterface[];
I receive no interfaces.
Shouldn't this somehow be linked? Is there a particular setting I'm forgetting?
My readstate function is:
private void ReadStateMobileNetwork()
{
Log.Info("Reading mobile network state");
try
{
MbnInterfaceManager mbnInfMgr = new MbnInterfaceManager();
IMbnInterfaceManager mbnInfMgrInterface = mbnInfMgr as IMbnInterfaceManager;
if (mbnInfMgrInterface != null)
{
IMbnInterface[] mobileInterfaces = mbnInfMgrInterface.GetInterfaces() as IMbnInterface[];
Log.Info("Interfaces: " + mobileInterfaces);
if (mobileInterfaces != null && mobileInterfaces.Length > 0)
{
// Use the first interface, as there should only be one mobile data adapter
IMbnSignal signalDetails = mobileInterfaces[0] as IMbnSignal;
Int32.TryParse(signalDetails.GetSignalStrength().ToString(), out _signalStrength);
SignalStrength = Convert.ToInt32(((float)SignalStrength / 33) * 100);
MBN_PROVIDER provider = mobileInterfaces[0].GetHomeProvider();
MobileProvider = provider.providerName.ToString();
if (String.IsNullOrEmpty(SIMkaartnumber))
{
try
{
IMbnSubscriberInformation subInfo = mobileInterfaces[0].GetSubscriberInformation();
if (subInfo != null)
{
SIMkaartnumber = subInfo.SimIccID;
}
else
{
Connected = false;
SIMkaartnumber = "";
MobileProvider = "Sim unreadable";
SignalStrength = 0;
State = MobileNetworkMonitorState.UnableToReadSimInfo;
}
}
catch (Exception)
{
Connected = false;
SIMkaartnumber = "";
MobileProvider = "Sim unreadable";
SignalStrength = 0;
State = MobileNetworkMonitorState.UnableToReadSimInfo;
}
}
// Register the connection events
uint cookie;
MbnConnectionManager connMgr = new MbnConnectionManager();
IConnectionPointContainer connPointContainer = connMgr as IConnectionPointContainer;
Guid IID_IMbnConnectionEvents = typeof(IMbnConnectionEvents).GUID;
IConnectionPoint connPoint;
connPointContainer.FindConnectionPoint(ref IID_IMbnConnectionEvents, out connPoint);
// Check whether the connection is active
IMbnConnection connection = mobileInterfaces[0].GetConnection();
if (connection != null)
{
MBN_ACTIVATION_STATE state;
connection.GetConnectionState(out state, out profileName);
switch (state)
{
case MBN_ACTIVATION_STATE.MBN_ACTIVATION_STATE_NONE:
Connected = false;
MobileProvider = "";
State = MobileNetworkMonitorState.Unknown;
break;
case MBN_ACTIVATION_STATE.MBN_ACTIVATION_STATE_ACTIVATING:
Connected = false;
State = MobileNetworkMonitorState.Connecting;
break;
case MBN_ACTIVATION_STATE.MBN_ACTIVATION_STATE_ACTIVATED:
Connected = true;
State = MobileNetworkMonitorState.Connected;
break;
case MBN_ACTIVATION_STATE.MBN_ACTIVATION_STATE_DEACTIVATED:
Connected = false;
State = MobileNetworkMonitorState.NoConnection;
break;
case MBN_ACTIVATION_STATE.MBN_ACTIVATION_STATE_DEACTIVATING:
Connected = false;
State = MobileNetworkMonitorState.Disconnecting;
break;
default:
Connected = false;
State = MobileNetworkMonitorState.Unknown;
StateInfo = state.ToString();
break;
}
}
else
{
Connected = false;
MobileProvider = "No connection";
SignalStrength = 0;
State = MobileNetworkMonitorState.ConnectionNotFound;
}
}
else
{
Connected = false;
MobileProvider = "No interfaces";
SignalStrength = 0;
State = MobileNetworkMonitorState.MobileInterfacesNotFound;
}
}
else
{
Connected = false;
MobileProvider = "Interfaces null";
SignalStrength = 0;
State = MobileNetworkMonitorState.mbnInfMgrInterfaceIsNull;
}
}
catch (Exception ex)
{
Log.Debug(ex);
if (ex.Message.Contains("SIM is not inserted."))
{
Connected = false;
MobileProvider = "No SIM";
SIMkaartnumber = "";
State = MobileNetworkMonitorState.NoSimInserted;
}
else if (ex.Message.Contains("0x7FF8FB70"))
{
Connected = false;
MobileProvider = "No device";
State = MobileNetworkMonitorState.DeviceNotFound;
}
else if (ex.Message.Contains("0x80070426"))
{
Connected = false;
MobileProvider = "Service not started";
State = MobileNetworkMonitorState.ServiceNotStarted;
}
else if (ex.Message.Contains("0x80070490"))
{
Connected = false;
MobileProvider = "Unknown problem";
State = MobileNetworkMonitorState.Unknown;
}
else
{
Connected = false;
MobileProvider = "Unknown problem";
State = MobileNetworkMonitorState.Unknown;
StateInfo = ex.Message;
}
SignalStrength = 0;
}
}
Thank you for your help. Hope someone experienced this problem before and can help me.
User contributions licensed under CC BY-SA 3.0