📄 ndistapi.c
字号:
* Optional Area code (can be null or null str)
* @parm LPCTSTR | szLocalPhoneNumber |
* The phone number.
* @parm BOOL | fDialable |
* Bool designating whether you want the Dialable or the
* Displayable string.
* @parm DWORD | dwTranslateOpts |
* Translate options, Normally this will be zero or
* LINETRANSLATEOPTION_FORCELD
*
* @comm
* This function will return either the Dialable or the DisplayAble
* phone number (On Pegasus they are usually the same).
*
* @ex An example of how to use this function follows |
* No Example
*
*/
LPTSTR
NdisTapiLineTranslateAddress (
PNDISWAN_ADAPTER pAdapter,
DWORD dwDeviceID,
DWORD dwCountryCode,
LPCTSTR szAreaCode,
LPCTSTR szLocalPhoneNumber,
BOOL fDialable,
DWORD dwFlags)
{
LPTSTR szTempStr;
DWORD dwLen;
LPTSTR szOutStr = NULL;
LPTSTR szPtr;
DWORD dwNeededSize;
NDIS_STATUS Status;
PNDIS_TAPI_LINE_TRANSLATE pLineTranslate;
PLINE_TRANSLATE_OUTPUT pLineTranslateOutput;
DEBUGMSG (ZONE_FUNCTION,
(TEXT("+NdisTapiLineTranslateAddress(%s DeviceId=%u CC=%u AreaCode=%s PN=%s)\n"),
pAdapter->szAdapterName, dwDeviceID, dwCountryCode, szAreaCode, szLocalPhoneNumber));
// Allocate a temp string, length of the strings + null, two spaces and
// the country code
dwLen = _tcslen(szAreaCode) + _tcslen(szLocalPhoneNumber) + 20;
szTempStr = LocalAlloc (LPTR, dwLen * sizeof(TCHAR));
if (NULL == szTempStr)
{
DEBUGMSG (ZONE_ERROR, (TEXT("-NdisTapiLineTranslateAddress: Cannot allocate szTempStr\r\n")));
return NULL;
}
//
// Go with szTempStr as our default result in case we are unable to get
// a translation from the miniport.
//
szOutStr = szTempStr;
if (szAreaCode && (szAreaCode[0] != TEXT('\0'))) {
StringCchPrintfW(szTempStr, dwLen, L"+%d (%s) %s", dwCountryCode, szAreaCode, szLocalPhoneNumber);
} else {
StringCchPrintfW(szTempStr, dwLen, L"+%d %s", dwCountryCode, szLocalPhoneNumber);
}
#define DWORD_ROUND(x) (((x)+3) & 0xFFFFFFFC)
dwNeededSize = sizeof(NDIS_TAPI_LINE_TRANSLATE) + DWORD_ROUND(dwLen*sizeof(TCHAR)) +
sizeof(LINE_TRANSLATE_OUTPUT);
do
{
pLineTranslate = LocalAlloc (LPTR, dwNeededSize);
if (!pLineTranslate)
break;
pLineTranslate->ulRequestID = 0;
pLineTranslate->ulDeviceID = dwDeviceID;
pLineTranslate->ulAddressInLen = dwLen;
pLineTranslate->ulCard = 0;
pLineTranslate->ulTranslateOptions = dwFlags;
// Copy the AddressIn into the structure.
memcpy (pLineTranslate->DataBuf, (char *)szTempStr, dwLen*sizeof(TCHAR));
pLineTranslate->ulLineTranslateOutputOffset = DWORD_ROUND(dwLen*sizeof(TCHAR));
pLineTranslateOutput = (PLINE_TRANSLATE_OUTPUT) (pLineTranslate->DataBuf+pLineTranslate->ulLineTranslateOutputOffset);
pLineTranslateOutput->ulTotalSize = dwNeededSize - ((char *)pLineTranslateOutput - (char *)pLineTranslate);
PppNdisDoSyncRequest (&Status,
pAdapter,
NdisRequestQueryInformation,
OID_TAPI_TRANSLATE_ADDRESS,
pLineTranslate,
dwNeededSize);
if (Status == NDIS_STATUS_SUCCESS)
{
// If we had enough space to get the whole translation, we are done
if (pLineTranslateOutput->ulNeededSize <= pLineTranslateOutput->ulTotalSize)
{
// Success
DEBUGMSG (ZONE_TRACE,
(TEXT("DialableString='%s' DisplayString='%s'\r\n"),
(LPBYTE)pLineTranslateOutput + pLineTranslateOutput->ulDialableStringOffset,
(LPBYTE)pLineTranslateOutput +
pLineTranslateOutput->ulDisplayableStringOffset));
if (fDialable) {
szPtr = (LPTSTR) ((LPBYTE)pLineTranslateOutput +
pLineTranslateOutput->ulDialableStringOffset);
} else {
szPtr = (LPTSTR) ((LPBYTE)pLineTranslateOutput +
pLineTranslateOutput->ulDisplayableStringOffset);
}
szOutStr = LocalAlloc (LPTR, sizeof(TCHAR)*(_tcslen(szPtr)+1));
if (szOutStr)
{
_tcscpy (szOutStr, szPtr);
LocalFree (szTempStr);
}
else
{
szOutStr = szTempStr;
}
dwNeededSize = 0;
}
else
{
// Otherwise increment our needed size and try again
dwNeededSize += pLineTranslateOutput->ulNeededSize - pLineTranslateOutput->ulTotalSize;
}
}
LocalFree (pLineTranslate);
} while (Status == NDIS_STATUS_SUCCESS && dwNeededSize);
DEBUGMSG (ZONE_FUNCTION, (TEXT("PPP: -NdisTapiLineTranslateAddress: returning '%s'\r\n"), szOutStr));
return szOutStr;
}
/*****************************************************************************
*
*
* @func LPTSTR | TapiLineConfigDialogEdit |
* Let the user modify the Device config data
*
* @rdesc Returns a DWORD.
*
* @parm DWORD | dwDeviceID |
* The Device ID to use
*
* @comm
*
* @ex An example of how to use this function follows |
* No Example
*
*/
DWORD
NdisTapiLineConfigDialogEdit (PNDISWAN_ADAPTER pAdapter, DWORD dwDeviceID,
HWND hwndOwner,
LPCTSTR szDeviceClass,
LPVOID pDeviceConfigIn,
DWORD dwSize,
LPVARSTRING pDeviceConfigOut)
{
DWORD dwDevClassLen;
DWORD dwNeededSize;
NDIS_STATUS Status;
PNDIS_TAPI_LINE_CONFIG_DIALOG_EDIT pConfigDialogEdit;
DWORD dwRetVal = STATUS_SUCCESS;
DWORD dwCurOffset;
PVAR_STRING pVarString;
PBYTE pLocalConfigIn = NULL;
DEBUGMSG (ZONE_FUNCTION,
(TEXT("+NdisTapiLineConfigDialogEdit (0x%X, 0x%X, 0x%X, 0x%X(%s),")
TEXT(" 0x%X %d 0x%X)\r\n"), pAdapter, dwDeviceID, hwndOwner,
szDeviceClass, (szDeviceClass) ? szDeviceClass : TEXT("NULL"),
pDeviceConfigIn, dwSize, pDeviceConfigOut));
// We allow people to pass in NULL/0 for the original struct. If they do we'll
// get the default
if (NULL == pDeviceConfigIn) {
dwRetVal = NdisTapiGetDevConfig (pAdapter, dwDeviceID, &(LPBYTE)pLocalConfigIn,
&dwSize);
if (STATUS_SUCCESS != dwRetVal) {
if (pLocalConfigIn) {
LocalFree (pLocalConfigIn);
}
DEBUGMSG (ZONE_ERROR,
(TEXT("-NdisTapiLineConfigDialogEdit: Error from NdisTapiGetDevConfig '%d'\r\n"),
dwRetVal));
return dwRetVal;
}
pDeviceConfigIn = pLocalConfigIn;
}
if (szDeviceClass) {
dwDevClassLen = _tcslen (szDeviceClass);
} else {
dwDevClassLen = 0;
}
dwNeededSize = sizeof(NDIS_TAPI_LINE_CONFIG_DIALOG_EDIT) +
DWORD_ROUND(dwDevClassLen) + DWORD_ROUND(dwSize) +
pDeviceConfigOut->dwTotalSize;
pConfigDialogEdit = LocalAlloc (LPTR, dwNeededSize);
if (NULL == pConfigDialogEdit) {
DEBUGMSG (ZONE_ERROR,
(TEXT("-NdisTapiLineConfigDialogEdit: Cannot allocate pConfigDialogEdit, returning default string\r\n")));
if (pLocalConfigIn) {
LocalFree (pLocalConfigIn);
}
return dwRetVal;
}
pConfigDialogEdit->ulRequestID = 0;
pConfigDialogEdit->ulDeviceID = dwDeviceID;
pConfigDialogEdit->hwndOwner = hwndOwner;
pConfigDialogEdit->ulDeviceClassLen = dwDevClassLen;
if (dwDevClassLen) {
memcpy (pConfigDialogEdit->DataBuf, (char *)szDeviceClass,
sizeof(TCHAR)*(dwDevClassLen+1));
dwCurOffset = DWORD_ROUND(sizeof(TCHAR)*(dwDevClassLen+1));
} else {
dwCurOffset = 0;
}
pConfigDialogEdit->ulConfigInOffset = dwCurOffset;
pConfigDialogEdit->ulConfigInSize = dwSize;
memcpy (pConfigDialogEdit->DataBuf + pConfigDialogEdit->ulConfigInOffset,
pDeviceConfigIn, dwSize);
dwCurOffset = DWORD_ROUND(dwCurOffset + dwSize);
pConfigDialogEdit->ulConfigOutOffset = dwCurOffset;
pVarString = (PVAR_STRING) (pConfigDialogEdit->DataBuf +
pConfigDialogEdit->ulConfigOutOffset);
memcpy ((char *)pVarString, (char *)pDeviceConfigOut, pDeviceConfigOut->dwTotalSize);
PppNdisDoSyncRequest (&Status,
pAdapter,
NdisRequestQueryInformation,
OID_TAPI_CONFIG_DIALOG_EDIT,
pConfigDialogEdit,
dwNeededSize);
if (Status != NDIS_STATUS_SUCCESS) {
DEBUGMSG (ZONE_ERROR,
(TEXT("-NdisTapiLineConfigDialogEdit: NdisRequest returned 0x%X\r\n"),
Status));
LocalFree (pConfigDialogEdit);
if (pLocalConfigIn) {
LocalFree (pLocalConfigIn);
}
return dwRetVal = Status;
} else {
// Copy the result back
memcpy ((char *)pDeviceConfigOut, (char *)pVarString, pVarString->ulTotalSize);
}
if (pConfigDialogEdit) {
LocalFree (pConfigDialogEdit);
}
if (pLocalConfigIn) {
LocalFree (pLocalConfigIn);
}
DEBUGMSG (ZONE_FUNCTION, (TEXT("-NdisTapiLineConfigDialogEdit: Success, returning '%d'\r\n"), dwRetVal));
return dwRetVal;
}
NDIS_STATUS
NdisTapiGetDevConfig(
PNDISWAN_ADAPTER pAdapter,
DWORD dwDeviceID,
LPBYTE *plpbDevConfig,
DWORD *pdwSize)
{
PNDIS_TAPI_GET_DEV_CONFIG pTapiGetDevConfig;
DWORD dwDevConfigSize;
DWORD dwDeviceClassSize = 0;
LPCSTR lpszDeviceClass = NULL;
NDIS_STATUS Status;
DEBUGMSG(ZONE_FUNCTION, (TEXT("+NdisTapiGetDevConfig\n")));
dwDevConfigSize = sizeof(VARSTRING);
if (lpszDeviceClass)
dwDeviceClassSize = strlen(lpszDeviceClass) + 1;
// Don't know the size required for the dev config going in, so we
// need to iterate, incrementing the dev config size on each iteration.
do
{
Status = NDIS_STATUS_RESOURCES;
pTapiGetDevConfig = (PNDIS_TAPI_GET_DEV_CONFIG)LocalAlloc(LPTR, sizeof(*pTapiGetDevConfig) + dwDevConfigSize + dwDeviceClassSize);
if (pTapiGetDevConfig)
{
//
// Build the request to send to the adapter
//
pTapiGetDevConfig->ulRequestID = 0;
pTapiGetDevConfig->ulDeviceID = dwDeviceID;
pTapiGetDevConfig->ulDeviceClassSize = dwDeviceClassSize;
pTapiGetDevConfig->ulDeviceClassOffset = offsetof(NDIS_TAPI_GET_DEV_CONFIG, DeviceConfig) + dwDevConfigSize;
if (lpszDeviceClass)
memcpy((LPBYTE)pTapiGetDevConfig + pTapiGetDevConfig->ulDeviceClassOffset, lpszDeviceClass, dwDeviceClassSize);
pTapiGetDevConfig->DeviceConfig.ulTotalSize = dwDevConfigSize;
PppNdisDoSyncRequest (&Status,
pAdapter,
NdisRequestQueryInformation,
OID_TAPI_GET_DEV_CONFIG,
pTapiGetDevConfig,
sizeof(*pTapiGetDevConfig) + dwDevConfigSize + dwDeviceClassSize);
if (Status == NDIS_STATUS_SUCCESS)
{
PVAR_STRING pVStr = &pTapiGetDevConfig->DeviceConfig;
if (pVStr->ulNeededSize <= pVStr->ulTotalSize)
{
// The buffer was big enough to get the whole dev config
*plpbDevConfig = LocalAlloc(LPTR, pTapiGetDevConfig->DeviceConfig.ulStringSize);
if (*plpbDevConfig)
{
*pdwSize = pTapiGetDevConfig->DeviceConfig.ulStringSize;
memcpy(*plpbDevConfig, ((LPBYTE)&pTapiGetDevConfig->DeviceConfig) + pTapiGetDevConfig->DeviceConfig.ulStringOffset, *pdwSize);
}
else
{
DEBUGMSG (ZONE_ERROR, (TEXT("!NdisTapiGetDevConfig: Unable to allocate %d bytes of memory for devconfig\n"), pTapiGetDevConfig->DeviceConfig.ulStringSize));
Status = NDIS_STATUS_RESOURCES;
}
LocalFree(pTapiGetDevConfig);
break;
}
// Dev config structure was not big enough. Increase size and try again
dwDevConfigSize = pVStr->ulNeededSize;
}
LocalFree(pTapiGetDevConfig);
}
} while (Status == NDIS_STATUS_SUCCESS);
DEBUGMSG(ZONE_FUNCTION, (TEXT("-NdisTapiGetDevConfig: Status=%x\n"), Status));
return Status;
}
NDIS_STATUS
NdisTapiSetDevConfig(macCntxt_t *pMac)
{
PNDIS_TAPI_SET_DEV_CONFIG pTapiSetDevConfig;
LPBYTE lpbDevConfig;
DWORD dwDevConfigSize;
NDIS_STATUS Status = NDIS_STATUS_RESOURCES;
DEBUGMSG(ZONE_FUNCTION, (TEXT("+NdisTapiSetDevConfig\n")));
lpbDevConfig = ((pppSession_t *)(pMac->session))->lpbDevConfig;
dwDevConfigSize = ((pppSession_t *)(pMac->session))->dwDevConfigSize;
pTapiSetDevConfig = (PNDIS_TAPI_SET_DEV_CONFIG)LocalAlloc(LPTR, sizeof(*pTapiSetDevConfig) + dwDevConfigSize);
if (pTapiSetDevConfig)
{
pTapiSetDevConfig->ulRequestID = 0;
pTapiSetDevConfig->ulDeviceID = pMac->dwDeviceID;
pTapiSetDevConfig->ulDeviceClassSize = 0;
pTapiSetDevConfig->ulDeviceClassOffset = 0;
pTapiSetDevConfig->ulDeviceConfigSize = dwDevConfigSize;
memcpy(&pTapiSetDevConfig->DeviceConfig[0], lpbDevConfig, dwDevConfigSize);
pppUnLock(pMac->session);
PppNdisDoSyncRequest (&Status,
pMac->pAdapter,
NdisRequestSetInformation,
OID_TAPI_SET_DEV_CONFIG,
pTapiSetDevConfig,
sizeof(*pTapiSetDevConfig) + dwDevConfigSize);
pppLock(pMac->session);
LocalFree(pTapiSetDevConfig);
}
DEBUGMSG(ZONE_FUNCTION, (TEXT("-NdisTapiSetDevConfig: Status=%x\n"), Status));
return Status;
}
NDIS_STATUS
NdisTapiLineOpen(
macCntxt_t *pMac)
{
NDIS_TAPI_OPEN TapiOpen;
NDIS_STATUS Status;
TapiOpen.ulRequestID = ((pppSession_t *)(pMac->session))->bIsServer;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -