📄 dial.c
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// This source code is licensed under Microsoft Shared Source License
// Version 1.0 for Windows CE.
// For a copy of the license visit http://go.microsoft.com/fwlink/?LinkId=3223.
//
// ******************************************************************
// **
// ******************************************************************
//
// dial.c The dialing state machine for Unimodem
//
// @doc EX_TSPI
//
// @topic TSPI |
//
// Tspi Stuff
//
//
#include "windows.h"
#include "types.h"
#include "memory.h"
#include "mcx.h"
#include "tspi.h"
#include "linklist.h"
#include "tspip.h"
#include "tapicomn.h"
#include "dial.h"
#include "termctrl.h"
#include "resource.h"
#include "windev.h"
// Functions from modem.c
extern LONG SignalCommMask(PTLINEDEV pLineDev);
extern void SetDCBfromDevMiniCfg(DCB * pDCB,PDEVMINICFG lpDevMiniCfg);
extern void WriteModemLog(PTLINEDEV pLineDev, UCHAR * szCommand, DWORD dwOp);
extern void SetDialerTimeouts(PTLINEDEV pLineDev);
// Unimodem thread priority
extern DWORD g_dwUnimodemThreadPriority;
// Some keys we read to get modem related info from registry
const WCHAR szSettings[] = TEXT("Settings");
const WCHAR szDialSuffix[] = TEXT("DialSuffix");
static const WCHAR szInit[] = TEXT("Init");
#define MAXINITKEYS 5
static const PWCHAR szInitNum[MAXINITKEYS] = {
TEXT("1"),
TEXT("2"),
TEXT("3"),
TEXT("4"),
TEXT("5")
};
//
// Reset system idle timer so device doesn't go to sleep in the middle of dialing.
//
void MdmResetIdleTimer(void)
{
HMODULE hCoreDLL;
FARPROC pfnSystemIdleTimerReset;
if (IsAPIReady(SH_WMGR)) {
hCoreDLL = (HMODULE)LoadLibrary(TEXT("COREDLL.DLL"));
if (hCoreDLL != NULL) {
if (pfnSystemIdleTimerReset = GetProcAddress(hCoreDLL, TEXT("SystemIdleTimerReset"))) {
pfnSystemIdleTimerReset();
}
FreeLibrary(hCoreDLL);
}
}
}
int strncmpi(char *dst, const char *src, long count)
{
while (count) {
if (toupper(*dst) != toupper(*src))
return 1;
if (*src == 0)
return 0;
dst++;
src++;
count--;
}
return 0;
}
/******************************************************************************
@doc INTERNAL
@api BOOL | ExpandMacros | Takes the string pszLine, and copies it to
lpszVal after expanding macros
@parm char * | pszRegResponse | ptr to response string from registry.
@parm char * | pszExpanded | ptr to buffer to copy string to w/ macros expanded
@parm DWORD * | pdwValLen | length of pszVal w/ expanded macros.
@rdesc Returns FALSE if a needed macro translation could not be found in the
pMacroXlations table, TRUE otherwise.
*****************************************************************************/
BOOL
ExpandMacros(
PWCHAR pszRegResponse,
PWCHAR pszExpanded,
DWORD cchExpanded,
MODEMMACRO * pMdmMacro
)
{
DWORD cchName;
DWORD cchVal;
DWORD i;
DEBUGMSG(ZONE_DIAL, (TEXT("UNIMODEM:+ExpandMacros : Original \"%s\"\r\n"), pszRegResponse ));
for (i = 0; ((i < cchExpanded) && (*pszRegResponse)); )
{
// check for a macro
if ( *pszRegResponse == LMSCH )
{
// <cr>
if (!wcsnicmp(pszRegResponse,CR_MACRO,CR_MACRO_LENGTH))
{
pszExpanded[i] = CR;
i++;
pszRegResponse += CR_MACRO_LENGTH;
continue;
}
// <lf>
if (!wcsnicmp(pszRegResponse,LF_MACRO,LF_MACRO_LENGTH))
{
pszExpanded[i] = LF;
i++;
pszRegResponse += LF_MACRO_LENGTH;
continue;
}
// <hxx>
if ((pszRegResponse[1] == 'h' || pszRegResponse[1] == 'H') &&
isxdigit(pszRegResponse[2]) &&
isxdigit(pszRegResponse[3]) &&
pszRegResponse[4] == RMSCH )
{
pszExpanded[i] = (unsigned char) ((ctox(pszRegResponse[2]) << 4) + ctox(pszRegResponse[3]));
i++;
pszRegResponse += 5;
continue;
}
// <macro>
if (pMdmMacro)
{
// Check for a matching macro.
cchName = wcslen(pMdmMacro->MacroName);
if (!wcsnicmp(pszRegResponse, pMdmMacro->MacroName, cchName))
{
cchVal = wcslen(pMdmMacro->MacroValue);
if (cchVal < (cchExpanded - i)) {
memcpy(&pszExpanded[i], pMdmMacro->MacroValue, cchVal * sizeof(WCHAR));
i += cchVal;
pszRegResponse += cchName;
continue;
} else {
DEBUGMSG(1, (L"UNIMODEM:ExpandMacros Macro expansion failed! Buffer too small.\n"));
break;
}
}
} // <macro>
} // LMSCH
// No matches, copy the character verbatim.
pszExpanded[i] = *pszRegResponse++;
i++;
} // for
pszExpanded[i] = 0;
DEBUGMSG( ZONE_DIAL, (TEXT("UNIMODEM:-ExpandMacros : Expanded \"%s\"\r\n"), pszExpanded ));
return TRUE;
}
PWCHAR
CreateDialCommands(
PTLINEDEV pLineDev,
BOOL *fOriginate
)
{
DWORD dwSize;
PWCHAR pszTemp;
PWCHAR pszDialPrefix; // ex. "ATX4DT" or "ATX3DT"
PWCHAR pszDialSuffix; // ex. ";<cr>"
PWCHAR pszOrigSuffix; // ex. "<cr>"
PWCHAR pszzDialCommands = NULL;
PWCHAR ptchSrc, ptchDest;
WCHAR pszShortTemp[2];
static const WCHAR szPrefix[] = TEXT("Prefix");
static const WCHAR szTerminator[] = TEXT("Terminator");
static const WCHAR szDialPrefix[] = TEXT("DialPrefix");
static const WCHAR szPulse[] = TEXT("Pulse");
static const WCHAR szTone[] = TEXT("Tone");
static const WCHAR *szDialType; // szTone or szPulse
static const WCHAR szBlindOff[] = TEXT("Blind_Off");
static const WCHAR szBlindOn[] = TEXT("Blind_On");
static const WCHAR *szBlindType; // szBlindOn or szBlindOff
if (NULL == pLineDev->szAddress) {
DEBUGMSG( 1, (TEXT("UNIMODEM:CreateDialCommands - pLineDev->szAddress == NULL!!!\r\n")));
return NULL;
}
DEBUGMSG( ZONE_DIAL, (TEXT("UNIMODEM:+CreateDialCommands - number %s\r\n"),
pLineDev->szAddress ? pLineDev->szAddress : TEXT("") ));
// Figure out fOriginate
ptchSrc = pLineDev->szAddress;
*fOriginate = TRUE;
while (*ptchSrc)
{
if (pLineDev->chContinuation == *ptchSrc) // usually a semicolon
{
*fOriginate = FALSE;
#ifdef DEBUG
// make sure the string is correctly formed.
if (ptchSrc[1])
{
DEBUGMSG(ZONE_DIAL, (TEXT("UNIMODEM: CreateDialCommands szPhoneNumber had a line continuation character not at the end.\r\n")));
}
#endif // DEBUG
}
ptchSrc++;
}
// Trim the command continuation character off the end, now that we know this is not an origination string.
if (!(*fOriginate))
{
DEBUGMSG(ZONE_DIAL, (TEXT("UNIMODEM:CreateDialCommands Non-originate string, trim trailing \"%c\"\r\n"),pLineDev->chContinuation));
#ifdef DEBUG
if (ptchSrc[-1] != pLineDev->chContinuation) // usually a semicolon
{
DEBUGMSG( ZONE_DIAL, (TEXT("UNIMODEM:CreateDialCommands made a bad assumption.\r\n")));
}
#endif // DEBUG
ptchSrc[-1] = 0;
}
// At this point, szPhoneNumber is just a string of digits to be dialed, with no semicolon at
// the end. Plus we know whether to originate or not.
// make some temp space
dwSize = ((pLineDev->dwMaxCmd + 1 + // pszTemp
pLineDev->dwMaxCmd + 1 + // pszDialPrefix
pLineDev->dwMaxCmd + 1 + // pszDialSuffix
pLineDev->dwMaxCmd + 1) // pszOrigSuffix
* SZWCHAR);
pszTemp = (PWCHAR)TSPIAlloc( dwSize );
if (!pszTemp)
{
DEBUGMSG( ZONE_DIAL, (TEXT("UNIMODEM:-CreateDialCommands : out of memory.\r\n")));
return NULL;
}
DEBUGMSG(ZONE_DIAL, (TEXT("UNIMODEM:CreateDialCommands Allocated %d bytes at x%X for tmp dial strings\r\n"),
dwSize, pszTemp));
pszDialPrefix = pszTemp + pLineDev->dwMaxCmd + 1;
pszDialSuffix = pszDialPrefix + pLineDev->dwMaxCmd + 1;
pszOrigSuffix = pszDialSuffix + pLineDev->dwMaxCmd + 1;
// read in prefix
dwSize = pLineDev->dwMaxCmd * SZWCHAR;
if (ERROR_SUCCESS !=
MdmRegGetValue( pLineDev,
szSettings,
szPrefix,
REG_SZ,
(PUCHAR)pszTemp,
&dwSize) )
{
goto Failure;
}
ExpandMacros(pszTemp, pszDialPrefix, pLineDev->dwMaxCmd, NULL);
if ( (MDM_BLIND_DIAL & pLineDev->DevMiniCfg.dwModemOptions) ||
(MDM_BLIND_DIAL & pLineDev->dwDialOptions) )
{ // Turn on blind dialing
szBlindType = szBlindOn;
DEBUGMSG( ZONE_DIAL,
(TEXT("UNIMODEM:CreateDialCommands BLIND DIALING - ModemOptions 0x%X, DialOptions 0x%X\r\n"),
pLineDev->DevMiniCfg.dwModemOptions, pLineDev->dwDialOptions ));
}
else
{ // Turn off blind dialing
szBlindType = szBlindOff;
}
#ifdef BLIND_OPTION_IN_PREFIX
// read in appropriate blind options
dwSize = pLineDev->dwMaxCmd * SZWCHAR;
if (ERROR_SUCCESS !=
MdmRegGetValue( pLineDev,
szSettings,
szBlindType,
REG_SZ,
(PUCHAR)pszTemp,
&dwSize) )
{
goto Failure;
}
ExpandMacros(pszTemp, pszDialPrefix + wcslen(pszDialPrefix), pLineDev->dwMaxCmd, NULL);
#endif
// read in dial prefix
dwSize = pLineDev->dwMaxCmd * SZWCHAR;
if (ERROR_SUCCESS != MdmRegGetValue( pLineDev,
szSettings,
szDialPrefix,
REG_SZ,
(PUCHAR)pszTemp,
&dwSize) )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -