⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ndisprot.c

📁 WinCE5.0部分核心源码
💻 C
📖 第 1 页 / 共 3 页
字号:
		case LINE_CREATE :
			if (AdapterAddRef(pAdapter))
			{
				if ((pTapiEvent->ulParam1+1) > pAdapter->dwNumDevices)
				{
					NdisTapiSetNumLineDevs(pAdapter, pTapiEvent->ulParam1 + 1);
					g_dwTotalLineCount++;
				}
				AdapterDelRef(pAdapter);
			} else {
				DEBUGMSG (ZONE_ERROR, (TEXT("PROTStatus: Invalid pAdapter?\r\n")));
				ASSERT (0);
			}
			break;

		case LINE_NEWCALL:
			DEBUGMSG (ZONE_PPP, (TEXT("PPP: LINE_NEWCALL\n")));
			pMac = (macCntxt_t *)pTapiEvent->htLine;

			if (s_p = PPPADDREFMAC(pMac, REF_LINE_NEWCALL))
			{
				//
				// Store the miniport driver's call handle, to be passed
				// on calls into the driver.
				//
				pMac->hCall = pTapiEvent->ulParam1;
				pMac->bCallClosed = FALSE;

				//
				// Return a transport driver call handle to the miniport for it
				// to use in subsequent indications for this call.
				//
				pTapiEvent->ulParam2 = (HTAPI_CALL)pMac;

				//
				// A LINE_CALLSTATE of OFFERING should follow soon.
				//
				
				PPPDELREF(s_p, REF_LINE_NEWCALL);
			}
			break;

		case LINE_CALLSTATE :
			pMac = (macCntxt_t *)pTapiEvent->htLine;

			DEBUGMSG (ZONE_MAC, (TEXT("PPP: LINE_CALLSTATE %d indication from MAC layer\n"), pTapiEvent->ulParam1));

			if (s_p = PPPADDREFMAC(pMac, REF_LINE_CALLSTATE))
			{
				pppLock(s_p);

				pMac->dwLineCallState = pTapiEvent->ulParam1;

				switch (pTapiEvent->ulParam1)
				{
				case LINECALLSTATE_CONNECTED :
					DEBUGMSG (ZONE_MAC, (TEXT("PPP: Callstate CONNECTED....\r\n")));

					if (s_p->bIsServer)
					{
						(void)NdisTapiGetDeviceIdAsync(pMac, LINECALLSELECT_CALL, TEXT("ndis"));
						PppHandleLineConnectedEvent(s_p);
					}
					else
					{
						pMac->TapiEcode = SUCCESS;
						SetEvent (pMac->hNdisTapiEvent);
					}
					break;

				case LINECALLSTATE_DISCONNECTED:
					//
					// The remote party has disconnected from the call.
					// ulParam2 contains additional info about the cause of
					// the disconnection as a LINEDISCONNECTMODE_XXX value.
					//
					DEBUGMSG (ZONE_MAC, (TEXT("PPP: Callstate DISCONNECTED %x\n"), pTapiEvent->ulParam2));
					switch (pTapiEvent->ulParam2)
					{
					case LINEDISCONNECTMODE_NORMAL:
						// This gets reported for a "NO CARRIER" during a connect attempt
						// Also when a connection is closed because we initiated it this
						// error occurs.
						if (pMac->TapiEcode == 0)
							pMac->TapiEcode = ERROR_NO_CARRIER;
						break;

					case LINEDISCONNECTMODE_BUSY:
						// The remote user's station is busy. 
						pMac->TapiEcode = ERROR_LINE_BUSY;
						break;

					case LINEDISCONNECTMODE_NOANSWER:
                        // The remote user's station does not answer. 
						pMac->TapiEcode = ERROR_NO_ANSWER;
						break;

					case LINEDISCONNECTMODE_NODIALTONE:
						// A dial tone was not detected
						pMac->TapiEcode = ERROR_NO_DIALTONE;
						break;

					case LINEDISCONNECTMODE_BADADDRESS:
						// The destination address is invalid.
						pMac->TapiEcode = ERROR_BAD_PHONE_NUMBER;
						break;

					case LINEDISCONNECTMODE_REJECT:
						// The remote user has rejected the call.
						pMac->TapiEcode = ERROR_REMOTE_DISCONNECTION;
						break;

					case LINEDISCONNECTMODE_UNREACHABLE:
						// The remote user could not be reached.
						pMac->TapiEcode = ERROR_NO_CARRIER;
						break;

					case LINEDISCONNECTMODE_UNAVAIL:
						// The port is in use by another process
						pMac->TapiEcode = ERROR_PORT_NOT_AVAILABLE;
						break;

					case LINEDISCONNECTMODE_UNKNOWN:
					case LINEDISCONNECTMODE_PICKUP:
					case LINEDISCONNECTMODE_FORWARDED:
					case LINEDISCONNECTMODE_CONGESTION:
					case LINEDISCONNECTMODE_INCOMPATIBLE:
					default:
						pMac->TapiEcode = ERROR_PORT_DISCONNECTED;
						break;
					}
					PppHandleLineDisconnectedEvent(s_p, pMac);
					break;

				case LINECALLSTATE_IDLE:
					//
					// The call exists but has not been connected.
					// No activity exists on the call, which means that no call is currently active.
					// A call can never transition out of the idle state. 
					// 
					DEBUGMSG (ZONE_MAC, (TEXT("PPP: Callstate IDLE....\n")));
					pMac->TapiEcode = ERROR_PORT_DISCONNECTED;
					PppHandleLineDisconnectedEvent(s_p, pMac);
					break;

				case LINECALLSTATE_DIALING :
				case LINECALLSTATE_DIALTONE :
				case LINECALLSTATE_PROCEEDING :
					DEBUGMSG (ZONE_MAC, (TEXT("PPP: Callstate DIAL....\r\n")));
					pppChangeOfState( pMac->session, RASCS_PortOpened, 0 );
					break;

				case LINECALLSTATE_BUSY :
					DEBUGMSG (ZONE_MAC, (TEXT("PPP: Callstate BUSY....\r\n")));
					pMac->TapiEcode = ERROR_LINE_BUSY;
					SetEvent (pMac->hNdisTapiEvent);
					break;

				case LINECALLSTATE_OFFERING :
					//
					// Answer the call
					//
					// This will typically result in a LINECALLSTATE_CONNECTED indication
					// from the miniport shortly.
					//
					DEBUGMSG (ZONE_PPP, (TEXT("PPP: ANSWERING\n")));
					if (s_p->bIsServer)
						(void)NdisTapiLineAnswer(pMac, NULL, 0);
					break;

				case LINECALLSTATE_UNKNOWN :
					// This is the initial state of a new call
					break;

				default:
					/*
					case LINECALLSTATE_ACCEPTED :
					case LINECALLSTATE_RINGBACK :
					case LINECALLSTATE_SPECIALINFO :
					case LINECALLSTATE_ONHOLD :
					case LINECALLSTATE_CONFERENCED :
					case LINECALLSTATE_ONHOLDPENDCONF :
					*/
					DEBUGMSG (ZONE_MAC, (TEXT("PPP: Unhandled Callstate %d...\r\n"),
										  pTapiEvent->ulParam1));
					ASSERT (0);
					break;
				}

				pppUnLock(s_p);

				PPPDELREF(s_p, REF_LINE_CALLSTATE);
			}
			break;
		case LINE_REPLY:
			pMac = (macCntxt_t *)pTapiEvent->htLine;

			if (s_p = PPPADDREFMAC(pMac, REF_LINE_REPLY))
			{
				DEBUGMSG (ZONE_MAC, (TEXT("PPP: LINE_REPLY: ulParam1=%d ulParam2=%d ulParam3=%d\r\n"),
							  pTapiEvent->ulParam1, pTapiEvent->ulParam2,
							  pTapiEvent->ulParam3));
				if (pTapiEvent->ulParam2 && (0 == pMac->TapiEcode)) {
					DEBUGMSG (ZONE_MAC, (TEXT("PPP: Got LineReply with error 0x%X and hadn't got previous LINECALLSTATE error\r\n"),
								  pTapiEvent->ulParam2));
					pMac->TapiEcode = ERROR_NO_ANSWER;
					SetEvent (pMac->hNdisTapiEvent);
				}
				PPPDELREF(s_p, REF_LINE_REPLY);
			}
			break;
				
		default :
			DEBUGMSG (ZONE_MAC, (TEXT("PPP: PROTStatus: Unhandled NDIS_STATUS_TAPI_INDICATION %d(0x%X)\r\n"),
						  pTapiEvent->ulMsg, pTapiEvent->ulMsg));
			break;
		}
		break;
	case NDIS_STATUS_WAN_LINE_UP :
		pMacLineUp = (PNDIS_MAC_LINE_UP)Status;
		ASSERT (StatusSize >= sizeof(NDIS_MAC_LINE_UP));
		DEBUGMSG (ZONE_MAC, (TEXT("PPP: PROTStatus: WAN Line Up\r\n")));
		DEBUGMSG (ZONE_MAC, (TEXT("  LinkSpeed = %d\r\n"), pMacLineUp->LinkSpeed));
		DEBUGMSG (ZONE_MAC, (TEXT("  Quality = %d (0=Raw, 1=ErrorControl, 2=Reliable)\r\n"), pMacLineUp->Quality));
		DEBUGMSG (ZONE_MAC, (TEXT("  SendWindow = %d\r\n"), pMacLineUp->SendWindow));
		DEBUGMSG (ZONE_MAC, (TEXT("  ConnectionWrapperID = 0x%X\r\n"), pMacLineUp->ConnectionWrapperID));
		DEBUGMSG (ZONE_MAC, (TEXT("  NdisLinkHandle = 0x%X\r\n"), pMacLineUp->NdisLinkHandle));
		
		pMac = (macCntxt_t *)pMacLineUp->ConnectionWrapperID;
		pMacLineUp->NdisLinkContext = pMac;	// For multi-link this will have to be different

		// Save info away.
		pMac->NdisLinkHandle = pMacLineUp->NdisLinkHandle;
		if (pMacLineUp->LinkSpeed) {
			pMac->LinkSpeed = pMacLineUp->LinkSpeed;
		} else {
			pMac->LinkSpeed = 288;	// Default speed
		}
		pMac->Quality = pMacLineUp->Quality;
		pMac->SendWindow = pMacLineUp->SendWindow;
		
		break;
	case NDIS_STATUS_WAN_LINE_DOWN :
		pMacLineDown = (PNDIS_MAC_LINE_DOWN)Status;
		ASSERT (StatusSize >= sizeof(NDIS_MAC_LINE_DOWN));
		DEBUGMSG (ZONE_MAC, (TEXT("PPP: PROTStatus: WAN Line Down\r\n")));
		
		pMac = (macCntxt_t *)pMacLineDown->NdisLinkContext;

		if (s_p = PPPADDREFMAC(pMac, REF_WAN_LINE_DOWN))
		{
			pppLock(s_p);
			pMac->TapiEcode = ERROR_PORT_DISCONNECTED;
			pppLcp_LowerLayerDown(s_p->lcpCntxt);
			pppUnLock(s_p);

			PPPDELREF(s_p, REF_WAN_LINE_DOWN);
		}
		break;

	case NDIS_STATUS_RESET_START:
		break;

	case NDIS_STATUS_RESET_END:
		break;
		
	default :
		DEBUGMSG (ZONE_WARN, (TEXT("PPP: WARNING - PROTStatus: Unhandled GStatus=%X\n"), GStatus));
		break;
		
	}
	DEBUGMSG (ZONE_FUNCTION, (TEXT("PPP: -PROTStatus:\r\n")));

}

//** PROTStatusComplete - PROT status complete handler.
//
//  A routine called by the NDIS driver so that we can do postprocessing
//  after a status event.
//
//  Entry:
//      Handle - The binding handle we specified (really a pointer to an AI).
//
//  Exit: Nothing.
//
void NDIS_API
PROTStatusComplete(NDIS_HANDLE Handle)
{
	DEBUGMSG (ZONE_FUNCTION, (TEXT("PPP: +PROTStatusComplete(0x%X)\r\n"),
							   Handle));

}

//*     PROTBindAdapter - Bind and initialize an adapter.
//
//      Called in a PNP environment to initialize and bind an adapter. We open
//      the adapter and get it running, and then we call up to IP to tell him
//      about it. IP will initialize, and if all goes well call us back to start
//      receiving.
//
//      Input:  RetStatus               - Where to return the status of this call.
//              BindContext             - Handle to use for calling BindAdapterComplete.
//				AdapterName             - Pointer to name of adapter.
//				SS1						- System specific 1 parameter.
//				SS2						- System specific 2 parameter.
//
//      Returns: Nothing.
//	
//		OmarM - modified for WinCE
void NDIS_API
PROTBindAdapter(
		OUT	PNDIS_STATUS	RetStatus,
	IN		NDIS_HANDLE		BindContext,
	IN		PNDIS_STRING	AdapterName,
	IN		PVOID			SS1,
	IN		PVOID			SS2)
{
	DEBUGMSG (ZONE_MAC, (L"PPP: +PROTBindAdapter(AdapterName)\n", AdapterName->Buffer));

	*RetStatus = AddAdapter(AdapterName);

	DEBUGMSG(ZONE_MAC, (L"PPP: -PROTBindAdapter %s Status=%x\n", AdapterName->Buffer, *RetStatus));
}

static void
pppSessionUnbindCloseComplete(
	PVOID	pData)
{
	HANDLE			hCloseCompleteEvent = (HANDLE)pData;

	DEBUGMSG(ZONE_MAC, (L"PPP: Unbind initiated pppSessionStop has completed\n"));
}

//*	PROTUnbindAdapter - Unbind from an adapter.
//
//	Called when we need to unbind from an adapter. We'll call up to IP to tell
//	him. When he's done, we'll free our memory and return.
//
//	Input:  RetStatus		- Where to return status from call.
//			ProtBindContext - The context we gave NDIS earlier - really a
//								pointer to an PROTInterface structure.
//			UnbindContext   - Context for completeing this request.
//
//	Returns: Nothing.
//
void NDIS_API
PROTUnbindAdapter(
		OUT	PNDIS_STATUS	RetStatus,
	IN		NDIS_HANDLE		ProtBindContext,
	IN		NDIS_HANDLE		UnbindContext)
{
	PNDISWAN_ADAPTER pAdapter = (PNDISWAN_ADAPTER)ProtBindContext;
	PPP_CONTEXT		*pContext;
	pppSession_t	*pSession;
	macCntxt_t		*pMac;

	DEBUGMSG (ZONE_INIT|ZONE_FUNCTION, 
		(TEXT("+PROTUnbindAdapter(0x%X, 0x%X, 0x%X)\r\n"),
				  RetStatus, ProtBindContext, UnbindContext));

	DEBUGMSG(ZONE_MAC, (L"PPP: Unbind adapter %s %x refcnt=%d\n", pAdapter->szAdapterName, pAdapter, pAdapter->dwRefCnt));

	*RetStatus = NDIS_STATUS_ADAPTER_NOT_FOUND;

	//
	//  Validate pAdapter
	//
	if (AdapterAddRef(pAdapter))
	{
		pAdapter->hUnbindContext = UnbindContext;

		//
		//	Prevent any new sessions from using the adapter
		//
		pAdapter->bClosingAdapter = TRUE;

		//
		//	Close any active sessions for the adapter
		//

		EnterCriticalSection (&v_ListCS);

		// Find the context in the global list
		for (pContext = pppContextList; pContext; pContext = pContext->Next)
		{
			if (pSession = pContext->Session)
			{
				if (pMac = (macCntxt_t *)(pSession->macCntxt))
				{
					if (pMac->pAdapter == pAdapter)
					{
						//
						// pSession is using the adapter from which
						// we are unbinding. Close the session.
						//
						DEBUGMSG(ZONE_MAC, (L"PPP: Stop session %s adapter %s\n", pSession->rasEntry.szDeviceName, pAdapter->szAdapterName));
						pppSessionStop(pSession, pppSessionUnbindCloseComplete, NULL);
					}
				}
			}
		}

		LeaveCriticalSection (&v_ListCS);

		//
		//	Delete the reference above,
		//  
		AdapterDelRef(pAdapter);

		//
		//	Delete the original reference from PROTBindAdapter
		//
		AdapterDelRef(pAdapter);

		//
		//  When all sessions on the adapter are closed,
		//  the last reference to the session will be removed.
		//	At that point, NdisCloseAdapter will be called.
		//	When the NdisCloseAdapter completes, we will
		//	call NdisCompleteUnbindAdapter.  At this point,
		//  just return NDIS_STATUS_PENDING.
		//
		*RetStatus = NDIS_STATUS_PENDING;

		DEBUGMSG(ZONE_MAC, (L"PPP: Unbind adapter %s Status=%d\n", pAdapter->szAdapterName, *RetStatus));
	}


	DEBUGMSG (ZONE_INIT|ZONE_FUNCTION, (TEXT("-PROTUnbindAdapter:\r\n")));
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -