Try the code sample below (warning this makes some assumptions about TAPI
buffer sizes that may need tweaking but that is because I did not want to
continuously negotiate with TAPI for buffer sizes). This sample outputs to a
console which may not be present on all CE/WM terminals. It will run anyway
but there will be no visible output. It works out dBm figures based on what
the AT command to the modem would have returned for the TAPI signal level
value provided.
===
#include <tapi.h>
#include <extapi.h>
#include <Ras.h>
TCHAR* LineStates[] =
{
TEXT("Unknown"),
TEXT("Off"),
TEXT("Rx Only"),
TEXT("Tx Only"),
TEXT("No Tx/Rx"),
TEXT("Full")
};
TCHAR* RegisterStates[] =
{
TEXT(""),
TEXT("Unknown"),
TEXT("Denied"),
TEXT("Not registered"),
TEXT("Registering"),
TEXT("Home"),
TEXT("Roaming"),
TEXT("Digital service"),
TEXT("Analog service")
};
TCHAR* GPRSClass[] =
{
TEXT("Unknown"),
TEXT("Voice & GPRS"),
TEXT("GSM data or GPRS"),
TEXT("Voice or GPRS"),
TEXT("GPRS only"),
TEXT("GSM only"),
};
TCHAR* SystemType[] =
{
TEXT("None"), // 0x00
TEXT("IS95A"), // 0x01
TEXT("IS95B"), // 0x02
TEXT("1XRTT"), // 0x04
TEXT("GSM"), // 0x08
TEXT("GPRS") // 0x10
};
const int TAPI_LOW_VERSION = 0x10003;
const int TAPI_HIGH_VERSION = 0x20002;
const int TAPI_LOW_EXT_VERSION = 0x10000;
const int TAPI_HIGH_EXT_VERSION = 0x10001;
void GetGPRSStatus( void )
{
HLINEAPP tapiHandle = 0;
DWORD numberDevices = 0;
DWORD tapiVersion = 0x00020000;
LINEINITIALIZEEXPARAMS lineInit;
DWORD tapiAPIVersion = 0;
DWORD tapiExtVersion = 0;
HLINE lineHandle = 0;
LONG err = 0;
lineInit.dwTotalSize = sizeof(LINEINITIALIZEEXPARAMS);
lineInit.dwOptions = LINEINITIALIZEEXOPTION_USEEVENT;
if( (err = lineInitializeEx( &tapiHandle, NULL, NULL, TEXT("GPRSStatus"),
&numberDevices, &tapiVersion, &lineInit)) == ERROR_SUCCESS )
{
for ( DWORD i = 0; i < numberDevices; i++ )
{
if ( (err = lineNegotiateAPIVersion( tapiHandle, i, TAPI_LOW_VERSION,
TAPI_HIGH_VERSION, &tapiAPIVersion, NULL )) == ERROR_SUCCESS )
{
if ( (err = lineNegotiateExtVersion( tapiHandle, i, tapiAPIVersion,
TAPI_LOW_EXT_VERSION, TAPI_HIGH_EXT_VERSION, &tapiExtVersion)) ==
ERROR_SUCCESS )
{
LINEDEVCAPS* lineDevCaps = (LINEDEVCAPS*) new char[sizeof(LINEDEVCAPS)
+ 1024];
lineDevCaps->dwTotalSize = sizeof(LINEDEVCAPS) + 1024;
if ( (err = lineGetDevCaps(tapiHandle, i, tapiAPIVersion,
tapiExtVersion, lineDevCaps)) == ERROR_SUCCESS )
{
if ( _wcsnicmp( (TCHAR*) (((char*) lineDevCaps) +
lineDevCaps->dwLineNameOffset), TEXT("Cellular Line"),
lineDevCaps->dwLineNameSize ) == 0 )
{
if ( (err = lineOpen( tapiHandle, i, &lineHandle, tapiAPIVersion,
tapiExtVersion, 0, LINECALLPRIVILEGE_MONITOR | LINECALLPRIVILEGE_OWNER,
LINEMEDIAMODE_INTERACTIVEVOICE | LINEMEDIAMODE_DATAMODEM, NULL )) ==
ERROR_SUCCESS )
{
LINEGENERALINFO* LineGeneralInfo = (LINEGENERALINFO*) new char[2048];
memset( LineGeneralInfo, 0, sizeof(LineGeneralInfo));
LineGeneralInfo->dwTotalSize = 2048;
if ( lineGetGeneralInfo( lineHandle, LineGeneralInfo ) ==
ERROR_SUCCESS)
{
TCHAR buffer[1024];
memset(buffer, 0, sizeof(buffer));
memcpy(buffer, ((char*) LineGeneralInfo) +
LineGeneralInfo->dwModelOffset, LineGeneralInfo->dwModelSize);
wprintf(TEXT("Model : %s\r\n"), buffer);
memset(buffer, 0, sizeof(buffer));
memcpy(buffer, ((char*) LineGeneralInfo) +
LineGeneralInfo->dwRevisionOffset, LineGeneralInfo->dwRevisionSize);
wprintf(TEXT("Revision : %s\r\n"), buffer);
}
delete[] LineGeneralInfo;
DWORD CurrentState = 0;
DWORD CurrentSupport = 0;
if ( lineGetEquipmentState( lineHandle, &CurrentState,
&CurrentSupport ) == ERROR_SUCCESS)
{
wprintf(TEXT("Radio Power: %s\r\n"), LineStates[CurrentState]);
}
DWORD RegisterStatus = 0;
lineGetRegisterStatus( lineHandle, &RegisterStatus );
wprintf(TEXT("Register : %s\r\n"), RegisterStates[RegisterStatus]);
LINEOPERATOR CurrentOperator;
if ( lineGetCurrentOperator( lineHandle, &CurrentOperator ) ==
ERROR_SUCCESS )
{
if (wcslen(CurrentOperator.lpszLongName) != 0 )
wprintf(TEXT("Network : %s\r\n"), CurrentOperator.lpszLongName);
else
wprintf(TEXT("Network : None\r\n"));
}
LINEDEVSTATUS DevStatus;
memset( &DevStatus, 0, sizeof(DevStatus));
DevStatus.dwTotalSize = sizeof(DevStatus);
if ( lineGetLineDevStatus(lineHandle, &DevStatus) == ERROR_SUCCESS)
{
int SignalLevel = 0;
if ( DevStatus.dwSignalLevel == 0 )
{
wprintf(TEXT("Signal : No signal\r\n") );
}
else if ( DevStatus.dwSignalLevel > 64225 )
{
wprintf(TEXT("Signal : >= 27 (-59)dBm\r\n") );
}
else
{
SignalLevel = (DevStatus.dwSignalLevel - 1310 ) / 2621 + 2;
int dBm = -113 + SignalLevel * 2;
wprintf(TEXT("Signal : %d (%d)dBm\r\n"), SignalLevel, dBm );
}
}
DWORD dwCurrentSystemType = 0;
if ( lineGetCurrentSystemType(lineHandle, &dwCurrentSystemType) ==
ERROR_SUCCESS)
{
if ( dwCurrentSystemType == 0 )
{
wprintf(TEXT("System Type: %s\r\n"),
SystemType[dwCurrentSystemType]);
}
else
{
wprintf(TEXT("System Type:"));
int i = 0x01;
int pos = 1;
while ( i < 0x020 )
{
if ( (i & dwCurrentSystemType) != 0 )
wprintf(TEXT(" %s"), SystemType[pos]);
i = i << 1;
++pos;
}
wprintf(TEXT("\r\n"));
}
}
DWORD dwClass = 0;
if ( lineGetGPRSClass(lineHandle, &dwClass) == ERROR_SUCCESS)
wprintf(TEXT("Class : %s\r\n"), GPRSClass[dwClass]);
err = lineClose( lineHandle );
delete[] lineDevCaps;
break;
}
}
}
delete[] lineDevCaps;
}
}
}
lineShutdown( tapiHandle );
}
}